changeset 47600:582f1e3159e8 condy-folding

check if class references to arrays exist at compile time and warn if that is not the case
author vromero
date Fri, 27 Oct 2017 15:05:48 -0400
parents 70f6e416e669
children 158c20a316f9
files src/jdk.compiler/share/classes/com/sun/tools/javac/util/Constables.java test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.java test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.out
diffstat 3 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Constables.java	Fri Oct 27 10:11:45 2017 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Constables.java	Fri Oct 27 15:05:48 2017 -0400
@@ -310,12 +310,20 @@
                 }
             }
             Type type = descriptorToType(descriptor, currentModule, false);
+            Symbol symToLoad;
             if (!type.hasTag(ARRAY)) {
-                try {
-                    type.tsym.complete();
-                } catch (CompletionFailure ex) {
-                    log.warning(tree, Warnings.ClassNotFound(type.tsym));
+                symToLoad = type.tsym;
+            } else {
+                Type elt = type;
+                while (elt.hasTag(ARRAY)) {
+                    elt = ((ArrayType)elt).elemtype;
                 }
+                symToLoad = elt.tsym;
+            }
+            try {
+                symToLoad.complete();
+            } catch (CompletionFailure ex) {
+                log.warning(tree, Warnings.ClassNotFound(symToLoad));
             }
             return type.hasTag(ARRAY) ? type : type.tsym;
         } else if (dynamicConstantClass.isInstance(constant)) {
--- a/test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.java	Fri Oct 27 10:11:45 2017 -0400
+++ b/test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.java	Fri Oct 27 15:05:48 2017 -0400
@@ -15,6 +15,9 @@
         ClassRef cr = ClassRef.ofDescriptor("LNonExistentClass2;");
         Class<?> c = ldc(cr);
 
+        ClassRef crArr = ClassRef.ofDescriptor("[[[LNonExistentClass3;");
+        Class<?> cArr = ldc(crArr);
+
         final MethodTypeRef mt2 = MethodTypeRef.of(ClassRef.ofDescriptor("Ljava/lang/String;"));
         // now the class exists but the method doesn't
         MethodHandle mh2 = ldc(MethodHandleRef.of(MethodHandleRef.Kind.STATIC, ClassRef.ofDescriptor("LWarningIfClassOrMemberNotFound;"), "bar", mt2));
--- a/test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.out	Fri Oct 27 10:11:45 2017 -0400
+++ b/test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.out	Fri Oct 27 15:05:48 2017 -0400
@@ -1,7 +1,8 @@
 WarningIfClassOrMemberNotFound.java:13:31: compiler.warn.class.not.found: NonExistentClass1
 WarningIfClassOrMemberNotFound.java:16:25: compiler.warn.class.not.found: NonExistentClass2
-WarningIfClassOrMemberNotFound.java:20:31: compiler.warn.member.not.found.at.class: bar, WarningIfClassOrMemberNotFound
-WarningIfClassOrMemberNotFound.java:24:31: compiler.warn.member.not.found.at.class: foo, WarningIfClassOrMemberNotFound
+WarningIfClassOrMemberNotFound.java:19:28: compiler.warn.class.not.found: NonExistentClass3
+WarningIfClassOrMemberNotFound.java:23:31: compiler.warn.member.not.found.at.class: bar, WarningIfClassOrMemberNotFound
+WarningIfClassOrMemberNotFound.java:27:31: compiler.warn.member.not.found.at.class: foo, WarningIfClassOrMemberNotFound
 - compiler.err.warnings.and.werror
 1 error
-4 warnings
+5 warnings