Skip to content

Commit

Permalink
8317336: Assertion error thrown during 'this' escape analysis
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
archiecobbs authored and Vicente Romero committed Oct 12, 2023
1 parent 16fd43c commit a8473b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,11 @@ public void visitForLoop(JCForLoop tree) {

@Override
public void visitForeachLoop(JCEnhancedForLoop tree) {
visitLooped(tree, super::visitForeachLoop);
visitLooped(tree, foreach -> {
scan(foreach.expr);
refs.discardExprs(depth); // we don't handle iterator() yet
scan(foreach.body);
});
}

@Override
Expand Down Expand Up @@ -729,7 +733,10 @@ public void visitReturn(JCReturn tree) {

@Override
public void visitLambda(JCLambda lambda) {
visitDeferred(() -> visitScoped(false, () -> super.visitLambda(lambda)));
visitDeferred(() -> visitScoped(false, () -> {
scan(lambda.body);
refs.discardExprs(depth); // needed in case body is a JCExpression
}));
}

@Override
Expand Down
16 changes: 16 additions & 0 deletions test/langtools/tools/javac/warnings/ThisEscape.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,4 +601,20 @@ public static final class Sub1 extends ThisEscapeSealed {
public static final class Sub2 extends ThisEscapeSealed {
}
}

// Verify no assertion error occurs (JDK-8317336)
public static class ThisEscapeAssertionError {
public ThisEscapeAssertionError() {
System.out.println((Supplier<Object>)() -> this);
}
}

// Verify no assertion error occurs (JDK-8317336)
public static class ThisEscapeAssertionError2 {
public ThisEscapeAssertionError2() {
ThisEscapeAssertionError2[] array = new ThisEscapeAssertionError2[] { this };
for (Object obj : array)
;
}
}
}

1 comment on commit a8473b7

@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.