Closed
Description
Description
Class cast is missing for the Object of private nested class.
To Reproduce
Steps to reproduce the behavior:
- IntelliJ IDEA 2022.1.4 is running with UTBot plugin installed
- Open a project with JDK 8/11
- Add the following class to it:
public class ABC {
private class NML {
public NML[] array = new NML[2];
NML() {
array[0] = null;
array[1] = null;
}
}
NML obj;
ABC() {
obj = new NML();
}
public int size() {
return obj.array.length;
}
}
- Open the generated test
Expected behavior
Generated tests are supposed to be compilable.
Class cast must be added to the instance of the nested class, like
ABC.NML nml = ((ABC.NML) createInstance("ABC$NML"));
Actual behavior
Class cast is missing for the NML Object created by means of reflection.
Visual proofs (screenshots, logs, images)
The following test is present:
public void testSize_ThrowNullPointerException_1() throws Exception {
ABC abc = new ABC();
Object nml = createInstance("ABC$NML");
setField(nml, "array", null);
abc.obj = nml;
/* This test fails because method [ABC.size] produces [java.lang.NullPointerException]
ABC.size(ABC.java:19) */
abc.size();
}
Environment
Windows 10 Pro
IntelliJ IDEA 2022.1.4
JDK 8
Additional context
If private modifier is removed - nested class is package-private or public - the class cast is made correctly.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done