JAVA: java.lang.IllegalArgumentException: impossible subclasses of the class of final classes [Lcom.package.testEntityDO;

im trying to execute mock below class.

public class testEntityDO extends BasetestDO { private String entityType; private testCapabilityDO[] capabilities; private testEntityDO[] testDOs; public String getEntityType() { return entityType; } public void setEntityType(String entityType) { this.entityType = entityType; } public testCapabilityDO[] getCapabilities() { return capabilities; } public void setCapabilities(testCapabilityDO[] capabilities) { this.capabilities = capabilities; } public TestEntityDO[] getTestPortDOs() { return testPortDOs; } public void setTestPortDOs(TestEntityDO[] testPortDOs) { this.testPortDOs = testPortDOs; } } 

Code for mixing:

 TestEntityDO[] testEntityMock = testmethod.getTestEntityDO(); 

Mocks me:

 TestEntityDO[] testEntityDOMock = PowerMock.createMock(TestEntityDO[].class); // exception is generating at this point EasyMock.expect(testmethod.getTestEntityDO()).andReturn(testEntityDOMock); 

exception tracing:

 java.lang.IllegalArgumentException: Cannot subclass final class class [Lcom.package.TestEntityDO; at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446) at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216) at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317) 

a class is not a final class. yet the exception is indicated as the final class. please help me solve this problem.

+5
source share
1 answer

You are trying to subclass / layout an array of TestEntityDO . Arrays are final.

+5
source

Source: https://habr.com/ru/post/1234473/


All Articles