diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java index 2dd054619e0..0dd32fd8eca 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java @@ -167,7 +167,7 @@ class ThisEscapeAnalyzer extends TreeScanner { /** Used to terminate recursion in {@link #invokeInvokable invokeInvokable()}. */ - private final Set>> invocations = new HashSet<>(); + private final Set>> invocations = new HashSet<>(); /** Snapshot of {@link #callStack} where a possible 'this' escape occurs. * If non-null, a 'this' escape warning has been found in the current @@ -590,7 +590,7 @@ class ThisEscapeAnalyzer extends TreeScanner { return; // Stop infinite recursion here - Pair> invocation = Pair.of(site, refs.clone()); + Pair> invocation = Pair.of(methodInfo.declaration, refs.clone()); if (!invocations.add(invocation)) return; diff --git a/test/langtools/tools/javac/warnings/ThisEscape.java b/test/langtools/tools/javac/warnings/ThisEscape.java index d6ae9f8e8f4..25402c2c547 100644 --- a/test/langtools/tools/javac/warnings/ThisEscape.java +++ b/test/langtools/tools/javac/warnings/ThisEscape.java @@ -617,4 +617,34 @@ public class ThisEscape { ; } } + + // Verify no infinite recursion loop occurs (JDK-8317818) + public static class ThisEscapeRecursionExplosion { + private Object obj; + public ThisEscapeRecursionExplosion() { + getObject(); + } + private Object getObject() { + if (this.obj == null) { + this.obj = new Object(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + getObject().hashCode(); + } + return this.obj; + } + } }