changeset 43139:1d768b91ae4b

8171325: NPE in Check.clearLocalClassNameIndexes Reviewed-by: mcimadamore
author vromero
date Wed, 11 Jan 2017 10:29:24 -0800
parents 680d378b9d64
children 1e40241dc2d4
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java langtools/test/tools/javac/T8171325/NPEClearingLocalClassNameIndexesTest.java langtools/test/tools/javac/T8171325/NPEClearingLocalClassNameIndexesTest.out
diffstat 3 files changed, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jan 11 10:59:57 2017 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jan 11 10:29:24 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -436,8 +436,10 @@
     }
 
     void clearLocalClassNameIndexes(ClassSymbol c) {
-        localClassNameIndexes.remove(new Pair<>(
-                c.owner.enclClass().flatname, c.name));
+        if (c.owner != null && c.owner.kind != NIL) {
+            localClassNameIndexes.remove(new Pair<>(
+                    c.owner.enclClass().flatname, c.name));
+        }
     }
 
     public void newRound() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8171325/NPEClearingLocalClassNameIndexesTest.java	Wed Jan 11 10:29:24 2017 -0800
@@ -0,0 +1,21 @@
+/*
+ * @test  /nodynamiccopyright/
+ * @bug 8171325
+ * @summary NPE in Check.clearLocalClassNameIndexes
+ * @compile/fail/ref=NPEClearingLocalClassNameIndexesTest.out -XDrawDiagnostics NPEClearingLocalClassNameIndexesTest.java
+ */
+
+import java.util.List;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public class NPEClearingLocalClassNameIndexesTest {
+    <A> void f(List<A> t) {}
+    <B, C> C g(C u, Function<B, C> v) { return null; }
+    <D> D g(Supplier<D> w) { return null; }
+
+    public void test() {
+        f(g((String) null, task -> g(new NoSuch() {})));
+        f(g((String) null, task -> g(new NoSuch<int>() {})));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8171325/NPEClearingLocalClassNameIndexesTest.out	Wed Jan 11 10:29:24 2017 -0800
@@ -0,0 +1,6 @@
+NPEClearingLocalClassNameIndexesTest.java:18:9: compiler.err.cant.apply.symbol: kindname.method, f, java.util.List<A>, java.lang.String, kindname.class, NPEClearingLocalClassNameIndexesTest, (compiler.misc.incompatible.upper.lower.bounds: C, java.lang.Object,java.util.List<A>, java.lang.String)
+NPEClearingLocalClassNameIndexesTest.java:18:42: compiler.err.cant.resolve.location: kindname.class, NoSuch, , , (compiler.misc.location: kindname.class, NPEClearingLocalClassNameIndexesTest, null)
+NPEClearingLocalClassNameIndexesTest.java:19:9: compiler.err.cant.apply.symbol: kindname.method, f, java.util.List<A>, java.lang.String, kindname.class, NPEClearingLocalClassNameIndexesTest, (compiler.misc.incompatible.upper.lower.bounds: C, java.lang.Object,java.util.List<A>, java.lang.String)
+NPEClearingLocalClassNameIndexesTest.java:19:42: compiler.err.cant.resolve.location: kindname.class, NoSuch, , , (compiler.misc.location: kindname.class, NPEClearingLocalClassNameIndexesTest, null)
+NPEClearingLocalClassNameIndexesTest.java:19:49: compiler.err.type.found.req: int, (compiler.misc.type.req.ref)
+5 errors