-
Bug
-
Resolution: Fixed
-
P4
-
19, 20
-
b26
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8297942 | 19.0.2 | Victor Rudometov | P4 | Closed | Won't Fix |
ADDITIONAL SYSTEM INFORMATION :
Applies to JDK 19 and JDK 20ea
A DESCRIPTION OF THE PROBLEM :
When using an invalid pattern matching construct, i.e. using a class without decomposition pattern, in a super constructor call, javac produces a NullPointerException (at compile-time) instead of an error message.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the provided example.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This should produce an error message that java.awt.Point has no deconstruction pattern.
ACTUAL -
java.lang.NullPointerException: Cannot read field "type" because "sym" is null
at jdk.compiler/com.sun.tools.javac.code.Types.asSuper(Types.java:2159)
at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1189)
at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1110)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1013)
at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4906)
at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1106)
at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1077)
at jdk.compiler/com.sun.tools.javac.code.Types.isCastable(Types.java:1655)
at jdk.compiler/com.sun.tools.javac.comp.Attr.checkCastablePattern(Attr.java:4148)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitRecordPattern(Attr.java:4223)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCRecordPattern.accept(JCTree.java:2459)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitTypeTest(Attr.java:4107)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCInstanceOf.accept(JCTree.java:2216)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:733)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitConditional(Attr.java:2000)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1519)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:500)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:480)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:467)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.lambda$processArg$0(ArgumentAttr.java:220)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:242)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:219)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.visitConditional(ArgumentAttr.java:255)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1519)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:197)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:685)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:788)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2507)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1799)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:740)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:2300)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1586)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:780)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1463)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1082)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1253)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5601)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5492)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5316)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5255)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
---------- BEGIN SOURCE ----------
class Base { int i; Base(int j) { i = j; } }
class Sub extends Base {
Sub(Object o) { super(o instanceof java.awt.Point(int x, int y)? x + y: 0); }
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
After identifying the invalidity of the construct without the compiler's help, just fix the error in the source code.
FREQUENCY : always
Applies to JDK 19 and JDK 20ea
A DESCRIPTION OF THE PROBLEM :
When using an invalid pattern matching construct, i.e. using a class without decomposition pattern, in a super constructor call, javac produces a NullPointerException (at compile-time) instead of an error message.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the provided example.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This should produce an error message that java.awt.Point has no deconstruction pattern.
ACTUAL -
java.lang.NullPointerException: Cannot read field "type" because "sym" is null
at jdk.compiler/com.sun.tools.javac.code.Types.asSuper(Types.java:2159)
at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1189)
at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1110)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1013)
at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4906)
at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1106)
at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1077)
at jdk.compiler/com.sun.tools.javac.code.Types.isCastable(Types.java:1655)
at jdk.compiler/com.sun.tools.javac.comp.Attr.checkCastablePattern(Attr.java:4148)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitRecordPattern(Attr.java:4223)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCRecordPattern.accept(JCTree.java:2459)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitTypeTest(Attr.java:4107)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCInstanceOf.accept(JCTree.java:2216)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:733)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitConditional(Attr.java:2000)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1519)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:500)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:480)
at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:467)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.lambda$processArg$0(ArgumentAttr.java:220)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:242)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:219)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.visitConditional(ArgumentAttr.java:255)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1519)
at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:197)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:685)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:788)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2507)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1799)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:740)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:2300)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1586)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:780)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1463)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1082)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1253)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5601)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5492)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5316)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5255)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
---------- BEGIN SOURCE ----------
class Base { int i; Base(int j) { i = j; } }
class Sub extends Base {
Sub(Object o) { super(o instanceof java.awt.Point(int x, int y)? x + y: 0); }
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
After identifying the invalidity of the construct without the compiler's help, just fix the error in the source code.
FREQUENCY : always
- backported by
-
JDK-8297942 NullPointerException with invalid pattern matching construct in constructor call
- Closed