Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2020-02-09 18:59:37 +0000
committerStephan Herrmann2020-02-09 19:01:35 +0000
commitc934b0402980c6fbcc23e78648f48c0ce54a2b14 (patch)
tree3d47b3cbb832345e6c47ca7af0c39281b97130c8
parent41c36b71d0f8c591ecbcd302250d5f0a4095a349 (diff)
downloadeclipse.jdt.core-c934b0402980c6fbcc23e78648f48c0ce54a2b14.tar.gz
eclipse.jdt.core-c934b0402980c6fbcc23e78648f48c0ce54a2b14.tar.xz
eclipse.jdt.core-c934b0402980c6fbcc23e78648f48c0ce54a2b14.zip
Bug 559951 - [10,11,12][compiler] NoSuchMethodError at runtime whenI20200210-1800
invoking method on multiple bounded typed lambda argument Change-Id: I6bbe839e83175bef6e7d3b3c6d14b9ea0cc47fbb
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java81
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java8
2 files changed, 86 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
index aac77c7aab..7390e53ffa 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2019 GK Software AG, and others.
+ * Copyright (c) 2013, 2020 GK Software AG, and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10085,4 +10085,83 @@ public void testBug508834_comment0() {
"----------\n";
runner.runNegativeTest();
}
+ public void testBug559951() {
+ if (this.complianceLevel < ClassFileConstants.JDK10) return; // uses 'var'
+ runConformTest(
+ new String[] {
+ "no/Demo.java",
+ "package no;\n" +
+ "public class Demo {\n" +
+ " static void broken_method_dispatch_on_bounded_type_in_lambda_argument_with_Eclipse_compiler() {\n" +
+ " WithMessageRecipients withRecipients = new Message(new EmailRecipient(\"Jane\", \"jane@example.com\"), new EmailRecipient(\"Joe\", \"joe@example.com\"));\n" +
+ "\n" +
+ " withRecipients.getMessageRecipients()\n" +
+ " .stream()\n" +
+ " .forEach(recipient -> System.out.println(recipient.getName() + \" <\" + recipient.getEmailAddress() + \">\"));\n" +
+ " }\n" +
+ " static void works_fine_in_for_loop() {\n" +
+ " WithMessageRecipients withRecipients = new Message(new EmailRecipient(\"Jane\", \"jane@example.com\"), new EmailRecipient(\"Joe\", \"joe@example.com\"));\n" +
+ "\n" +
+ " for (var recipient : withRecipients.getMessageRecipients()) {\n" +
+ " System.out.println(recipient.getName() + \" <\" + recipient.getEmailAddress() + \">\");\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ " works_fine_in_for_loop();\n" +
+ " broken_method_dispatch_on_bounded_type_in_lambda_argument_with_Eclipse_compiler();\n" +
+ " }\n" +
+ "}\n",
+ "no/WithName.java",
+ "package no;\n" +
+ "public interface WithName {\n" +
+ " String getName();\n" +
+ "}",
+ "no/WithEmailAddress.java",
+ "package no;\n" +
+ "public interface WithEmailAddress {\n" +
+ " String getEmailAddress();\n" +
+ "}\n",
+ "no/WithMessageRecipients.java",
+ "package no;\n" +
+ "import java.util.List;\n" +
+ "public interface WithMessageRecipients {\n" +
+ " <CONTACT extends WithName & WithEmailAddress> List<? extends CONTACT> getMessageRecipients();\n" +
+ "}",
+ "no/EmailRecipient.java",
+ "package no;\n" +
+ "public class EmailRecipient implements WithName, WithEmailAddress {\n" +
+ " private final String name;\n" +
+ " private final String emailAddress;\n" +
+ " public EmailRecipient(String name, String emailAddress) {\n" +
+ " this.name = name;\n" +
+ " this.emailAddress = emailAddress;\n" +
+ " }\n" +
+ " @Override\n" +
+ " public String getEmailAddress() {\n" +
+ " return emailAddress;\n" +
+ " }\n" +
+ " @Override\n" +
+ " public String getName() {\n" +
+ " return name;\n" +
+ " }\n" +
+ "}",
+ "no/Message.java",
+ "package no;\n" +
+ "import java.util.List;\n" +
+ "public class Message implements WithMessageRecipients {\n" +
+ " private final List<EmailRecipient> recipients;\n" +
+ " public Message(EmailRecipient ... recipients) {\n" +
+ " this.recipients = List.of(recipients);\n" +
+ " }\n" +
+ " @Override\n" +
+ " public List<EmailRecipient> getMessageRecipients() {\n" +
+ " return recipients;\n" +
+ " }\n" +
+ "}"
+ },
+ "Jane <jane@example.com>\n" +
+ "Joe <joe@example.com>\n" +
+ "Jane <jane@example.com>\n" +
+ "Joe <joe@example.com>");
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
index 42b9d2600a..5ccf643ab9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3426,6 +3426,10 @@ public static TypeBinding getConstantPoolDeclaringClass(Scope currentScope, Meth
&& (options.complianceLevel >= ClassFileConstants.JDK1_4 || !(isImplicitThisReceiver && codegenBinding.isStatic()))
&& codegenBinding.declaringClass.id != TypeIds.T_JavaLangObject) // no change for Object methods
|| !codegenBinding.declaringClass.canBeSeenBy(currentScope)) {
+ TypeBinding erasedReceiverType = actualReceiverType.erasure();
+ if (erasedReceiverType.isIntersectionType18()) {
+ actualReceiverType = erasedReceiverType; // need to peel the intersecting types below
+ }
if (actualReceiverType.isIntersectionType18()) {
TypeBinding[] intersectingTypes = ((IntersectionTypeBinding18)actualReceiverType).getIntersectingTypes();
for(int i = 0; i < intersectingTypes.length; i++) {
@@ -3435,7 +3439,7 @@ public static TypeBinding getConstantPoolDeclaringClass(Scope currentScope, Meth
}
}
} else {
- constantPoolDeclaringClass = actualReceiverType.erasure();
+ constantPoolDeclaringClass = erasedReceiverType;
}
}
}

Back to the top