Skip to content

Commit

Permalink
8333169: javac NullPointerException record.type
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
lahodaj committed May 31, 2024
1 parent e930bc1 commit 32ee252
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
Original file line number Diff line number Diff line change
Expand Up @@ -6025,6 +6025,19 @@ public void visitBindingPattern(JCBindingPattern that) {
super.visitBindingPattern(that);
}

@Override
public void visitRecordPattern(JCRecordPattern that) {
initTypeIfNeeded(that);
if (that.record == null) {
that.record = new ClassSymbol(0, TreeInfo.name(that.deconstructor),
that.type, syms.noSymbol);
}
if (that.fullComponentTypes == null) {
that.fullComponentTypes = List.nil();
}
super.visitRecordPattern(that);
}

@Override
public void visitNewClass(JCNewClass that) {
if (that.constructor == null) {
Expand Down
31 changes: 30 additions & 1 deletion test/langtools/tools/javac/patterns/Exhaustiveness.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* @test
* @bug 8262891 8268871 8274363 8281100 8294670 8311038 8311815 8325215
* @bug 8262891 8268871 8274363 8281100 8294670 8311038 8311815 8325215 8333169
* @summary Check exhaustiveness of switches over sealed types.
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
Expand Down Expand Up @@ -2076,6 +2076,35 @@ static int r(R r) {
""");
}

@Test //JDK-8333169
public void testFlowForNestedSwitch(Path base) throws Exception {
doTest(base,
new String[0],
"""
class Main {
record A() {};
public static void main(String[] args) {
A a1 = new A();
A a2 = new A();
String causesCompilationError = log(
switch(a1) {
case A() -> switch(a2) {
case A() -> "A";
};
}
);
}
static <T> T log(T t) {
System.out.println("LOG: " + t);
return t;
}
}""");
}

private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException {
doTest(base, libraryCode, testCode, false, expectedErrors);
}
Expand Down

1 comment on commit 32ee252

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.