Bug 506749: ClassCastException in
BaseAllocationExpression.internalCheckGenerate
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index 8e7d097..b2efb25 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -11274,9 +11274,13 @@
((AbstractMethodDeclaration)enclosingMethod).binding.readableName());
else
arguments[0] = new String(((AbstractMethodDeclaration)enclosingMethod).selector);
- else
+ else if (this.referenceContext instanceof TypeDeclaration)
arguments[0] = "<clinit> of "+ //$NON-NLS-1$
new String(((TypeDeclaration)this.referenceContext).binding.readableName());
+ else if (this.referenceContext instanceof LambdaExpression)
+ arguments[0] = this.referenceContext.toString();
+ else
+ arguments[0] = "<unexpected source location>"; //$NON-NLS-1$
this.handle(
IProblem.BaseCtorInWrongMethod,
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 59ca850..3beee8e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -1016,7 +1016,7 @@
1204101 = Cannot invoke the lifting constructor {0} to create an externalized role (OTJLD 2.4.1(a)).
1204102 = Argument to lifting constructor {0} is not a freshly created base object (of type {1}); may cause a DuplicateRoleException at runtime (OTJLD 2.4.1(c)).
-1204201 = Illegal base constructor call: method {0} is not a constructor of a bound role (OTJLD 2.4.2).
+1204201 = Illegal base constructor call: enclosing ''{0}'' is not a constructor of a bound role (OTJLD 2.4.2).
1204202 = Illegal call to base constructor: this constructor is a lifting constructor (OTJLD 2.4.2).
1204203 = Cannot use this constructor from class {0}, because it creates a base instance of type {2} wheras a base instance of type {1} is required (OTJLD 2.4.2(c)).
1204204 = Constructor call (tsuper) must be the first statement in a role constructor (OTJLD 2.4.2).
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java8.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java8.java
index b3fade6..f9ec700 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java8.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java8.java
@@ -415,4 +415,46 @@
true, // flush
options);
}
+
+ public void testBug506749a() {
+ runNegativeTest(
+ new String[] {
+ "Bug506749.java",
+ "public team class Bug506749 {\n" +
+ " protected class R {\n" +
+ " void test() {\n" +
+ " Runnable r = () -> base();\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in Bug506749.java (at line 4)\n" +
+ " Runnable r = () -> base();\n" +
+ " ^^^^\n" +
+ "Illegal base constructor call: enclosing '() -> <no expression yet>' is not a constructor of a bound role (OTJLD 2.4.2).\n" +
+ "----------\n");
+ }
+
+ public void testBug506749b() {
+ runNegativeTest(
+ new String[] {
+ "Bug506749.java",
+ "public team class Bug506749 {\n" +
+ " protected class R {\n" +
+ " void test() {\n" +
+ " Runnable r = () -> { base(); };\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in Bug506749.java (at line 4)\n" +
+ " Runnable r = () -> { base(); };\n" +
+ " ^^^^\n" +
+ "Illegal base constructor call: enclosing \'() -> {\n" +
+ " <no expression yet>;\n" +
+ "}\' is not a constructor of a bound role (OTJLD 2.4.2).\n" +
+ "----------\n");
+ }
}