Bug 498362 - Compile error on Optional.map(byte[]::clone) (edit)
- fix for a regression
Change-Id: Ic903a7214f773f0fd3e39a80bbcc064d7b4bab5b
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 d410696..d553532 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
@@ -6784,7 +6784,7 @@
"}\n"
});
}
-public void testBug498362() {
+public void testBug498362_comment0() {
runConformTest(
new String[] {
"X.java",
@@ -6800,4 +6800,32 @@
"}\n"
});
}
+public void testBug498362_comment5() {
+ runConformTest(
+ new String[] {
+ "CloneVerifyError.java",
+ "public class CloneVerifyError {\n" +
+ " public interface PublicCloneable<T> extends Cloneable {\n" +
+ " public T clone();\n" +
+ " }\n" +
+ "\n" +
+ " public static <T> T[] clone0(T[] input) {\n" +
+ " return input == null ? null : input.clone();\n" +
+ " }\n" +
+ "\n" +
+ " public static <T extends PublicCloneable<T>> T clone0(T input) {\n" +
+ " if (input == null) {\n" +
+ " return null;\n" +
+ " } else {\n" +
+ " return input.clone();\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " Object[] array = null;\n" +
+ " clone0(array);\n" +
+ " }\n" +
+ "}\n"
+ });
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
index 1e5da30..c9dc409 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
@@ -401,16 +401,16 @@
MethodBinding originalBinding = this.binding.original();
TypeBinding originalType = originalBinding.returnType;
// extra cast needed if method return type is type variable
- if (originalType.leafComponentType().isTypeVariable()) {
+ if (ArrayBinding.isArrayClone(this.actualReceiverType, this.binding)
+ && runtimeTimeType.id != TypeIds.T_JavaLangObject
+ && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
+ // from 1.5 source level on, array#clone() resolves to array type, but codegen to #clone()Object - thus require extra inserted cast
+ this.valueCast = runtimeTimeType;
+ } else if (originalType.leafComponentType().isTypeVariable()) {
TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
? compileTimeType // unboxing: checkcast before conversion
: runtimeTimeType;
this.valueCast = originalType.genericCast(targetType);
- } else if (ArrayBinding.isArrayClone(this.actualReceiverType, this.binding)
- && runtimeTimeType.id != TypeIds.T_JavaLangObject
- && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
- // from 1.5 source level on, array#clone() resolves to array type, but codegen to #clone()Object - thus require extra inserted cast
- this.valueCast = runtimeTimeType;
}
if (this.valueCast instanceof ReferenceBinding) {
ReferenceBinding referenceCast = (ReferenceBinding) this.valueCast;