< prev index next >

src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java

Print this page

        

@@ -141,12 +141,24 @@
                 this.implIsInstanceMethod = true;
                 break;
             case REF_invokeSpecial:
                 // JDK-8172817: should use referenced class here, but we don't know what it was
                 this.implClass = implInfo.getDeclaringClass();
-                this.implKind = REF_invokeSpecial;
                 this.implIsInstanceMethod = true;
+
+                // Classes compiled prior to dynamic nestmate support invokes a private instance
+                // method with REF_invokeSpecial.
+                //
+                // invokespecial should only be used to invoke private nestmate constructors.
+                // The lambda proxy class will be defined as a nestmate of targetClass.
+                // If the method to be invoked is an instance method of targetClass, then
+                // convert to use invokevirtual or invokeinterface.
+                if (targetClass == implClass && !implInfo.getName().equals("<init>")) { 
+                    this.implKind = implClass.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
+                } else {
+                    this.implKind = REF_invokeSpecial;
+                }
                 break;
             case REF_invokeStatic:
             case REF_newInvokeSpecial:
                 // JDK-8172817: should use referenced class here for invokestatic, but we don't know what it was
                 this.implClass = implInfo.getDeclaringClass();
< prev index next >