-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
9, 10, 11
-
x86_64
-
generic
ADDITIONAL SYSTEM INFORMATION :
Windows 10 x64, Java 9.0.1, 9.0.4, 10.0.1
A DESCRIPTION OF THE PROBLEM :
When the attached code is compiled with target 8 with JDK 9.0.1+ or JDK 10.0.4+, the compiler places an Objects.requireNonNull call when instantiating an inner class off of a parent class.
This causes tools such as AnimalSniffer to report an error on the instantiation when the API usage should be limited to Java 6 only. When compiling with target 6, target 9 or target 10, there is no such call generated. Similarly, when compiling with Java 8u151 and target 8, there is no such call.
I don't know if Java 11 does this too because currently the tools I'm using don't run on it yet.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached example program with Java 9 target 8. Inspect the generated class file for Objects.requireNonNull
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No calls to Objects.requiredNonNull
ACTUAL -
Call to Objects.requiredNonNull generated in the class file
---------- BEGIN SOURCE ----------
public class ObjNullCheck {
static class A {
class B {
}
}
public static void main(String[] args) {
A a = new A();
A.B b = a.new B();
System.out.println(b);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use parentInstance.new InnerClass() but have a method on the parent class create an inner instance.
FREQUENCY : always
Windows 10 x64, Java 9.0.1, 9.0.4, 10.0.1
A DESCRIPTION OF THE PROBLEM :
When the attached code is compiled with target 8 with JDK 9.0.1+ or JDK 10.0.4+, the compiler places an Objects.requireNonNull call when instantiating an inner class off of a parent class.
This causes tools such as AnimalSniffer to report an error on the instantiation when the API usage should be limited to Java 6 only. When compiling with target 6, target 9 or target 10, there is no such call generated. Similarly, when compiling with Java 8u151 and target 8, there is no such call.
I don't know if Java 11 does this too because currently the tools I'm using don't run on it yet.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached example program with Java 9 target 8. Inspect the generated class file for Objects.requireNonNull
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No calls to Objects.requiredNonNull
ACTUAL -
Call to Objects.requiredNonNull generated in the class file
---------- BEGIN SOURCE ----------
public class ObjNullCheck {
static class A {
class B {
}
}
public static void main(String[] args) {
A a = new A();
A.B b = a.new B();
System.out.println(b);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use parentInstance.new InnerClass() but have a method on the parent class create an inner instance.
FREQUENCY : always