changeset 48737:c890e3f259d8 condy-folding

trust the user on interface method references even if the owner is not an interface
author vromero
date Fri, 12 Jan 2018 14:45:38 -0500
parents 47ea1a11205e
children 8d1c08b46091
files src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties src/jdk.compiler/share/classes/com/sun/tools/javac/util/Constables.java test/langtools/tools/javac/specialConstantFolding/IndyCrashTest.out test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.out
diffstat 4 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Jan 12 11:08:16 2018 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Jan 12 14:45:38 2018 -0500
@@ -3211,9 +3211,9 @@
 compiler.warn.class.not.found=\
     could not find class file for class: {0}
 
-# 0: name, 1: symbol
+# 0: name, 1: string, 2: symbol
 compiler.warn.member.not.found.at.class=\
-    could not find member {0} at class {1}
+    could not find member {0} at {1} {2}
 
 # 0: symbol
 compiler.warn.incorrect.staticness.for.symbol=\
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Constables.java	Fri Jan 12 11:08:16 2018 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Constables.java	Fri Jan 12 14:45:38 2018 -0500
@@ -26,13 +26,14 @@
 package com.sun.tools.javac.util;
 
 import java.lang.reflect.Array;
-import java.lang.reflect.Field;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.nio.charset.Charset;
 
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.Scope.WriteableScope;
 import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import com.sun.tools.javac.code.Symbol.CompletionFailure;
@@ -63,6 +64,7 @@
 import com.sun.tools.javac.tree.TreeInfo;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 
+import static com.sun.tools.javac.code.Flags.INTERFACE;
 import static com.sun.tools.javac.code.Flags.STATIC;
 import static com.sun.tools.javac.code.TypeTag.ARRAY;
 import static com.sun.tools.javac.tree.JCTree.Tag.SELECT;
@@ -280,6 +282,7 @@
             String methodTypeDesc = (String)invokeMethodReflectively(methodTypeRefClass, mtConstant, "descriptorString");
             MethodType mType = (MethodType)descriptorToType(
                     methodTypeDesc, currentModule, true);
+            // this method generates fake symbols as needed
             Symbol refSymbol = getReferenceSymbol(refKind, ownerType.tsym, name, mType);
             boolean ownerFound = true;
             try {
@@ -289,6 +292,7 @@
                 ownerFound = false;
             }
             if (ownerFound) {
+                ownerType = refSymbol.owner.type;
                 checkIfMemberExists(tree, attrEnv, names.fromString(name), ownerType, mType.argtypes, refKind);
             }
             Pool.MethodHandle mHandle = new Pool.MethodHandle(refKind, refSymbol, types,
@@ -359,7 +363,8 @@
                 try {
                     refSym = rs.resolveInternalField(pos, attrEnv, qual, name);
                 } catch (Throwable t) {
-                    log.warning(pos, Warnings.MemberNotFoundAtClass(name, qual.tsym));
+                    log.warning(pos, Warnings.MemberNotFoundAtClass(name,
+                            (qual.tsym.flags_field & INTERFACE) == 0 ? "class" : "interface", qual.tsym));
                     return;
                 }
             }
@@ -411,6 +416,14 @@
             case ClassFile.REF_invokeStatic:
             case ClassFile.REF_invokeSpecial:
             case ClassFile.REF_invokeInterface:
+                if (refKind == ClassFile.REF_invokeInterface && (owner.flags_field & INTERFACE) == 0) {
+                    // we need a new owner for the symbol
+                    ClassSymbol newOwner = new ClassSymbol(owner.flags_field | Flags.INTERFACE, owner.name, syms.noSymbol);
+                    Symbol newMS = new MethodSymbol(flags, symbolName, methodType, newOwner);
+                    newOwner.members_field = WriteableScope.create(newOwner);
+                    newOwner.members_field.enter(newMS);
+                    return newMS;
+                }
                 return new MethodSymbol(flags, symbolName, methodType, owner);
             case ClassFile.REF_putField:
                 return new VarSymbol(flags, symbolName, methodType.argtypes.tail.head, owner);
--- a/test/langtools/tools/javac/specialConstantFolding/IndyCrashTest.out	Fri Jan 12 11:08:16 2018 -0500
+++ b/test/langtools/tools/javac/specialConstantFolding/IndyCrashTest.out	Fri Jan 12 14:45:38 2018 -0500
@@ -1,4 +1,4 @@
-IndyCrashTest.java:26:57: compiler.warn.member.not.found.at.class: foo, IndyCrashTest.IntrinsicTestHelper
+IndyCrashTest.java:26:57: compiler.warn.member.not.found.at.class: foo, class, IndyCrashTest.IntrinsicTestHelper
 IndyCrashTest.java:26:58: compiler.err.method.handle.not.suitable.indy: ()java.lang.invoke.CallSite
 1 error
 1 warning
--- a/test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.out	Fri Jan 12 11:08:16 2018 -0500
+++ b/test/langtools/tools/javac/specialConstantFolding/warningNotFoundOrIncorrect/WarningIfClassOrMemberNotFound.out	Fri Jan 12 14:45:38 2018 -0500
@@ -1,8 +1,8 @@
 WarningIfClassOrMemberNotFound.java:13:31: compiler.warn.class.not.found: NonExistentClass1
 WarningIfClassOrMemberNotFound.java:16:25: compiler.warn.class.not.found: NonExistentClass2
 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
+WarningIfClassOrMemberNotFound.java:23:31: compiler.warn.member.not.found.at.class: bar, class, WarningIfClassOrMemberNotFound
+WarningIfClassOrMemberNotFound.java:27:31: compiler.warn.member.not.found.at.class: foo, class, WarningIfClassOrMemberNotFound
 - compiler.err.warnings.and.werror
 1 error
 5 warnings