diff options
author | Sasikanth Bharadwaj | 2014-07-02 04:12:06 +0000 |
---|---|---|
committer | ssankaran | 2014-07-02 04:12:06 +0000 |
commit | 8bd886e250da1d7ba05246af4bcb8cd1f0eb1b1d (patch) | |
tree | a77e746b138650c7ef509b71472bc6016806ae06 | |
parent | 70c8245b6347e2f711f3e53a216dadae773b6920 (diff) | |
download | eclipse.jdt.core-8bd886e250da1d7ba05246af4bcb8cd1f0eb1b1d.tar.gz eclipse.jdt.core-8bd886e250da1d7ba05246af4bcb8cd1f0eb1b1d.tar.xz eclipse.jdt.core-8bd886e250da1d7ba05246af4bcb8cd1f0eb1b1d.zip |
Fixed Bug 436542 - Eclipse 4.4 compiler generates "bad class file"
according to javac
Signed-off-by: Sasikanth Bharadwaj <saammana@in.ibm.com>
2 files changed, 72 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java index 825a1ed313..8500c04a15 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java @@ -14,8 +14,15 @@ *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; +import java.io.File; import java.util.Map; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.IAttributeNamesConstants; +import org.eclipse.jdt.core.util.IClassFileAttribute; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IMethodInfo; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import junit.framework.Test; @@ -4434,6 +4441,70 @@ public void test434297() { "}" }); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=436542 : Eclipse 4.4 compiler generates "bad class file" according to javac +public void test436542() throws Exception { + String jreDirectory = Util.getJREDirectory(); + String jfxJar = Util.toNativePath(jreDirectory + "/lib/ext/jfxrt.jar"); + this.runConformTest( + new String[] { + "Utility.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "import javafx.collections.ListChangeListener;\n" + + "import javafx.collections.ObservableList;\n" + + "public class Utility {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " public static <T, R> List<R> mapList(Collection<T> original, Function<T, R> func) {\n" + + " return original.stream().map(func).collect(Collectors.toList());\n" + + " }\n" + + " /**\n" + + " * \"Binds\" the destination list to the observable source list with a transformation function applied.\n" + + " * Whenever the source list changes, the destination list is altered to match by applying\n" + + " * the given function to each element in the source list.\n" + + " */\n" + + " public static <S, T> void bindMap(List<T> dest, ObservableList<S> src, Function<S, T> func) {\n" + + " dest.clear();\n" + + " dest.addAll(mapList(src, func));\n" + + " src.addListener((ListChangeListener<S>) changes -> {\n" + + " while (changes.next()) {\n" + + " if (changes.wasPermutated() || changes.wasUpdated()) {\n" + + " // Same code for updated, replaced and permutation, just recalc the range:\n" + + " for (int i = changes.getFrom(); i < changes.getTo(); i++)\n" + + " dest.set(i, func.apply(src.get(i)));\n" + + " } else {\n" + + " for (int i = 0; i < changes.getRemovedSize(); i++)\n" + + " dest.remove(changes.getFrom());\n" + + " for (int i = 0; i < changes.getAddedSubList().size();i++)\n" + + " dest.add(i + changes.getFrom(), func.apply(changes.getAddedSubList().get(i)));\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}", + }, + "Success", + Util.concatWithClassLibs(new String[]{jfxJar,OUTPUT_DIR}, false), + true, + null); + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "Utility.class", IClassFileReader.ALL); + IMethodInfo lambdaMethod = null; + IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); + int length = methodInfos.length; + for (int i = 0; i < length; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if ("lambda$0".equals(new String(methodInfo.getName()))) { + lambdaMethod = methodInfo; + break; + } + } + assertNotNull("Could not find lambda method",lambdaMethod); + IClassFileAttribute signature = org.eclipse.jdt.internal.core.util.Util.getAttribute(lambdaMethod, IAttributeNamesConstants.SIGNATURE); + assertNull("Found generic signature for lambda method", signature); +} public static Class testClass() { return LambdaExpressionsTest.class; } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java index bc49d10f90..0a2001089a 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java @@ -359,7 +359,7 @@ public class SyntheticMethodBinding extends MethodBinding { this.lambda = lambda; this.declaringClass = declaringClass; this.selector = lambdaName; - this.modifiers = lambda.binding.modifiers; + this.modifiers = lambda.binding.modifiers & ~ExtraCompilerModifiers.AccGenericSignature; this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved) | (lambda.binding.tagBits & TagBits.HasParameterAnnotations); this.returnType = lambda.binding.returnType; this.parameters = lambda.binding.parameters; |