[Painless] Add boxed type to boxed type casts for method/return (#36571)

This adds implicit boxed type to boxed types casts for non-def types to create asymmetric casting relative to the def type when calling methods or returning values. This means that a user calling a method taking an Integer can call it with a Byte, Short, etc. legally which matches the way def works. This creates consistency in the casting model that did not previously exist.
This commit is contained in:
Jack Conradson 2018-12-17 10:50:19 -08:00 committed by GitHub
parent cd632de116
commit a0e7e571e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 573 additions and 133 deletions

View File

@ -73,38 +73,6 @@ public final class AnalyzerCaster {
} else if (expected == Double.class) {
return PainlessCast.originalTypetoTargetType(def.class, Double.class, explicit);
}
} else if (actual == Object.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxTargetType(Object.class, Byte.class, true, byte.class);
} else if (expected == short.class && explicit && internal) {
return PainlessCast.unboxTargetType(Object.class, Short.class, true, short.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxTargetType(Object.class, Character.class, true, char.class);
} else if (expected == int.class && explicit && internal) {
return PainlessCast.unboxTargetType(Object.class, Integer.class, true, int.class);
} else if (expected == long.class && explicit && internal) {
return PainlessCast.unboxTargetType(Object.class, Long.class, true, long.class);
} else if (expected == float.class && explicit && internal) {
return PainlessCast.unboxTargetType(Object.class, Float.class, true, float.class);
} else if (expected == double.class && explicit && internal) {
return PainlessCast.unboxTargetType(Object.class, Double.class, true, double.class);
}
} else if (actual == Number.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxTargetType(Number.class, Byte.class, true, byte.class);
} else if (expected == short.class && explicit && internal) {
return PainlessCast.unboxTargetType(Number.class, Short.class, true, short.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxTargetType(Number.class, Character.class, true, char.class);
} else if (expected == int.class && explicit && internal) {
return PainlessCast.unboxTargetType(Number.class, Integer.class, true, int.class);
} else if (expected == long.class && explicit && internal) {
return PainlessCast.unboxTargetType(Number.class, Long.class, true, long.class);
} else if (expected == float.class && explicit && internal) {
return PainlessCast.unboxTargetType(Number.class, Float.class, true, float.class);
} else if (expected == double.class && explicit && internal) {
return PainlessCast.unboxTargetType(Number.class, Double.class, true, double.class);
}
} else if (actual == String.class) {
if (expected == char.class && explicit) {
return PainlessCast.originalTypetoTargetType(String.class, char.class, true);
@ -140,8 +108,6 @@ public final class AnalyzerCaster {
return PainlessCast.boxTargetType(byte.class, byte.class, explicit, byte.class);
} else if (expected == Short.class && internal) {
return PainlessCast.boxTargetType(byte.class, short.class, explicit, short.class);
} else if (expected == Character.class && explicit && internal) {
return PainlessCast.boxTargetType(byte.class, char.class, true, char.class);
} else if (expected == Integer.class && internal) {
return PainlessCast.boxTargetType(byte.class, int.class, explicit, int.class);
} else if (expected == Long.class && internal) {
@ -170,12 +136,8 @@ public final class AnalyzerCaster {
return PainlessCast.originalTypetoTargetType(short.class, float.class, explicit);
} else if (expected == double.class) {
return PainlessCast.originalTypetoTargetType(short.class, double.class, explicit);
} else if (expected == Byte.class && explicit && internal) {
return PainlessCast.boxTargetType(short.class, byte.class, true, byte.class);
} else if (expected == Short.class && internal) {
return PainlessCast.boxTargetType(short.class, short.class, explicit, short.class);
} else if (expected == Character.class && explicit && internal) {
return PainlessCast.boxTargetType(short.class, char.class, true, char.class);
} else if (expected == Integer.class && internal) {
return PainlessCast.boxTargetType(short.class, int.class, explicit, int.class);
} else if (expected == Long.class && internal) {
@ -206,10 +168,6 @@ public final class AnalyzerCaster {
return PainlessCast.originalTypetoTargetType(char.class, float.class, explicit);
} else if (expected == double.class) {
return PainlessCast.originalTypetoTargetType(char.class, double.class, explicit);
} else if (expected == Byte.class && explicit && internal) {
return PainlessCast.boxTargetType(char.class, byte.class, true, byte.class);
} else if (expected == Short.class && internal) {
return PainlessCast.boxTargetType(char.class, short.class, explicit, short.class);
} else if (expected == Character.class && internal) {
return PainlessCast.boxTargetType(char.class, char.class, true, char.class);
} else if (expected == Integer.class && internal) {
@ -240,12 +198,6 @@ public final class AnalyzerCaster {
return PainlessCast.originalTypetoTargetType(int.class, float.class, explicit);
} else if (expected == double.class) {
return PainlessCast.originalTypetoTargetType(int.class, double.class, explicit);
} else if (expected == Byte.class && explicit && internal) {
return PainlessCast.boxTargetType(int.class, byte.class, true, byte.class);
} else if (expected == Short.class && explicit && internal) {
return PainlessCast.boxTargetType(int.class, short.class, true, short.class);
} else if (expected == Character.class && explicit && internal) {
return PainlessCast.boxTargetType(int.class, char.class, true, char.class);
} else if (expected == Integer.class && internal) {
return PainlessCast.boxTargetType(int.class, int.class, explicit, int.class);
} else if (expected == Long.class && internal) {
@ -274,14 +226,6 @@ public final class AnalyzerCaster {
return PainlessCast.originalTypetoTargetType(long.class, float.class, explicit);
} else if (expected == double.class) {
return PainlessCast.originalTypetoTargetType(long.class, double.class, explicit);
} else if (expected == Byte.class && explicit && internal) {
return PainlessCast.boxTargetType(long.class, byte.class, true, byte.class);
} else if (expected == Short.class && explicit && internal) {
return PainlessCast.boxTargetType(long.class, short.class, true, short.class);
} else if (expected == Character.class && explicit && internal) {
return PainlessCast.boxTargetType(long.class, char.class, true, char.class);
} else if (expected == Integer.class && explicit && internal) {
return PainlessCast.boxTargetType(long.class, int.class, true, int.class);
} else if (expected == Long.class && internal) {
return PainlessCast.boxTargetType(long.class, long.class, explicit, long.class);
} else if (expected == Float.class && internal) {
@ -308,16 +252,6 @@ public final class AnalyzerCaster {
return PainlessCast.originalTypetoTargetType(float.class, long.class, true);
} else if (expected == double.class) {
return PainlessCast.originalTypetoTargetType(float.class, double.class, explicit);
} else if (expected == Byte.class && explicit && internal) {
return PainlessCast.boxTargetType(float.class, byte.class, true, byte.class);
} else if (expected == Short.class && explicit && internal) {
return PainlessCast.boxTargetType(float.class, short.class, true, short.class);
} else if (expected == Character.class && explicit && internal) {
return PainlessCast.boxTargetType(float.class, char.class, true, char.class);
} else if (expected == Integer.class && explicit && internal) {
return PainlessCast.boxTargetType(float.class, int.class, true, int.class);
} else if (expected == Long.class && explicit && internal) {
return PainlessCast.boxTargetType(float.class, long.class, true, long.class);
} else if (expected == Float.class && internal) {
return PainlessCast.boxTargetType(float.class, float.class, explicit, float.class);
} else if (expected == Double.class && internal) {
@ -342,18 +276,6 @@ public final class AnalyzerCaster {
return PainlessCast.originalTypetoTargetType(double.class, long.class, true);
} else if (expected == float.class && explicit) {
return PainlessCast.originalTypetoTargetType(double.class, float.class, true);
} else if (expected == Byte.class && explicit && internal) {
return PainlessCast.boxTargetType(double.class, byte.class, true, byte.class);
} else if (expected == Short.class && explicit && internal) {
return PainlessCast.boxTargetType(double.class, short.class, true, short.class);
} else if (expected == Character.class && explicit && internal) {
return PainlessCast.boxTargetType(double.class, char.class, true, char.class);
} else if (expected == Integer.class && explicit && internal) {
return PainlessCast.boxTargetType(double.class, int.class, true, int.class);
} else if (expected == Long.class && explicit && internal) {
return PainlessCast.boxTargetType(double.class, long.class, true, long.class);
} else if (expected == Float.class && explicit && internal) {
return PainlessCast.boxTargetType(double.class, float.class, true, float.class);
} else if (expected == Double.class && internal) {
return PainlessCast.boxTargetType(double.class, double.class, explicit, double.class);
}
@ -366,8 +288,6 @@ public final class AnalyzerCaster {
return PainlessCast.unboxOriginalType(byte.class, byte.class, explicit, byte.class);
} else if (expected == short.class && internal) {
return PainlessCast.unboxOriginalType(byte.class, short.class, explicit, byte.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxOriginalType(byte.class, char.class, true, byte.class);
} else if (expected == int.class && internal) {
return PainlessCast.unboxOriginalType(byte.class, int.class, explicit, byte.class);
} else if (expected == long.class && internal) {
@ -376,14 +296,20 @@ public final class AnalyzerCaster {
return PainlessCast.unboxOriginalType(byte.class, float.class, explicit, byte.class);
} else if (expected == double.class && internal) {
return PainlessCast.unboxOriginalType(byte.class, double.class, explicit, byte.class);
} else if (expected == Short.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, byte.class, short.class);
} else if (expected == Integer.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, byte.class, int.class);
} else if (expected == Long.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, byte.class, long.class);
} else if (expected == Float.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, byte.class, float.class);
} else if (expected == Double.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, byte.class, double.class);
}
} else if (actual == Short.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxOriginalType(short.class, byte.class, true, short.class);
} else if (expected == short.class && internal) {
if (expected == short.class && internal) {
return PainlessCast.unboxOriginalType(short.class, short.class, explicit, short.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxOriginalType(short.class, char.class, true, short.class);
} else if (expected == int.class && internal) {
return PainlessCast.unboxOriginalType(short.class, int.class, explicit, short.class);
} else if (expected == long.class && internal) {
@ -392,13 +318,17 @@ public final class AnalyzerCaster {
return PainlessCast.unboxOriginalType(short.class, float.class, explicit, short.class);
} else if (expected == double.class && internal) {
return PainlessCast.unboxOriginalType(short.class, double.class, explicit, short.class);
} else if (expected == Integer.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, short.class, int.class);
} else if (expected == Long.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, short.class, long.class);
} else if (expected == Float.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, short.class, float.class);
} else if (expected == Double.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, short.class, double.class);
}
} else if (actual == Character.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxOriginalType(char.class, byte.class, true, char.class);
} else if (expected == short.class && explicit && internal) {
return PainlessCast.unboxOriginalType(char.class, short.class, true, char.class);
} else if (expected == char.class && internal) {
if (expected == char.class && internal) {
return PainlessCast.unboxOriginalType(char.class, char.class, explicit, char.class);
} else if (expected == int.class && internal) {
return PainlessCast.unboxOriginalType(char.class, int.class, explicit, char.class);
@ -408,15 +338,17 @@ public final class AnalyzerCaster {
return PainlessCast.unboxOriginalType(char.class, float.class, explicit, char.class);
} else if (expected == double.class && internal) {
return PainlessCast.unboxOriginalType(char.class, double.class, explicit, char.class);
} else if (expected == Integer.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, char.class, int.class);
} else if (expected == Long.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, char.class, long.class);
} else if (expected == Float.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, char.class, float.class);
} else if (expected == Double.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, char.class, double.class);
}
} else if (actual == Integer.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxOriginalType(int.class, byte.class, true, int.class);
} else if (expected == short.class && explicit && internal) {
return PainlessCast.unboxOriginalType(int.class, short.class, true, int.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxOriginalType(int.class, char.class, true, int.class);
} else if (expected == int.class && internal) {
if (expected == int.class && internal) {
return PainlessCast.unboxOriginalType(int.class, int.class, explicit, int.class);
} else if (expected == long.class && internal) {
return PainlessCast.unboxOriginalType(int.class, long.class, explicit, int.class);
@ -424,61 +356,45 @@ public final class AnalyzerCaster {
return PainlessCast.unboxOriginalType(int.class, float.class, explicit, int.class);
} else if (expected == double.class && internal) {
return PainlessCast.unboxOriginalType(int.class, double.class, explicit, int.class);
} else if (expected == Long.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, int.class, long.class);
} else if (expected == Float.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, int.class, float.class);
} else if (expected == Double.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, int.class, double.class);
}
} else if (actual == Long.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxOriginalType(long.class, byte.class, true, long.class);
} else if (expected == short.class && explicit && internal) {
return PainlessCast.unboxOriginalType(long.class, short.class, true, long.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxOriginalType(long.class, char.class, true, long.class);
} else if (expected == int.class && explicit && internal) {
return PainlessCast.unboxOriginalType(long.class, int.class, true, long.class);
} else if (expected == long.class && internal) {
if (expected == long.class && internal) {
return PainlessCast.unboxOriginalType(long.class, long.class, explicit, long.class);
} else if (expected == float.class && internal) {
return PainlessCast.unboxOriginalType(long.class, float.class, explicit, long.class);
} else if (expected == double.class && internal) {
return PainlessCast.unboxOriginalType(long.class, double.class, explicit, long.class);
} else if (expected == Float.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, long.class, float.class);
} else if (expected == Double.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, long.class, double.class);
}
} else if (actual == Float.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxOriginalType(float.class, byte.class, true, float.class);
} else if (expected == short.class && explicit && internal) {
return PainlessCast.unboxOriginalType(float.class, short.class, true, float.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxOriginalType(float.class, char.class, true, float.class);
} else if (expected == int.class && explicit && internal) {
return PainlessCast.unboxOriginalType(float.class, int.class, true, float.class);
} else if (expected == long.class && explicit && internal) {
return PainlessCast.unboxOriginalType(float.class, long.class, true, float.class);
} else if (expected == float.class && internal) {
if (expected == float.class && internal) {
return PainlessCast.unboxOriginalType(float.class, float.class, explicit, float.class);
} else if (expected == double.class && internal) {
return PainlessCast.unboxOriginalType(float.class, double.class, explicit, float.class);
} else if (expected == Double.class && internal) {
return PainlessCast.unboxOriginalTypeToBoxTargetType(explicit, float.class, double.class);
}
} else if (actual == Double.class) {
if (expected == byte.class && explicit && internal) {
return PainlessCast.unboxOriginalType(double.class, byte.class, true, double.class);
} else if (expected == short.class && explicit && internal) {
return PainlessCast.unboxOriginalType(double.class, short.class, true, double.class);
} else if (expected == char.class && explicit && internal) {
return PainlessCast.unboxOriginalType(double.class, char.class, true, double.class);
} else if (expected == int.class && explicit && internal) {
return PainlessCast.unboxOriginalType(double.class, int.class, true, double.class);
} else if (expected == long.class && explicit && internal) {
return PainlessCast.unboxOriginalType(double.class, long.class, true, double.class);
} else if (expected == float.class && explicit && internal) {
return PainlessCast.unboxOriginalType(double.class, float.class, true, double.class);
} else if (expected == double.class && internal) {
if (expected == double.class && internal) {
return PainlessCast.unboxOriginalType(double.class, double.class, explicit, double.class);
}
}
if ( actual == def.class ||
if (
actual == def.class ||
(actual != void.class && expected == def.class) ||
expected.isAssignableFrom(actual) ||
(actual.isAssignableFrom(expected) && explicit)) {
expected.isAssignableFrom(actual) ||
(actual.isAssignableFrom(expected) && explicit)
) {
return PainlessCast.originalTypetoTargetType(actual, expected, explicit);
} else {
throw location.createError(new ClassCastException("Cannot cast from " +

View File

@ -154,6 +154,10 @@ public final class MethodWriter extends GeneratorAdapter {
invokeStatic(UTILITY_TYPE, CHAR_TO_STRING);
} else if (cast.originalType == String.class && cast.targetType == char.class) {
invokeStatic(UTILITY_TYPE, STRING_TO_CHAR);
} else if (cast.unboxOriginalType != null && cast.boxTargetType != null) {
unbox(getType(cast.unboxOriginalType));
writeCast(cast.unboxOriginalType, cast.boxTargetType);
box(getType(cast.boxTargetType));
} else if (cast.unboxOriginalType != null) {
unbox(getType(cast.unboxOriginalType));
writeCast(cast.originalType, cast.targetType);

View File

@ -75,6 +75,15 @@ public class PainlessCast {
return new PainlessCast(originalType, targetType, explicitCast, null, null, null, boxTargetType);
}
/** Create a cast where the original type is unboxed, cast to a target type, and the target type is boxed. */
public static PainlessCast unboxOriginalTypeToBoxTargetType(boolean explicitCast, Class<?> unboxOriginalType, Class<?> boxTargetType) {
Objects.requireNonNull(unboxOriginalType);
Objects.requireNonNull(boxTargetType);
return new PainlessCast(null, null, explicitCast, unboxOriginalType, null, null, boxTargetType);
}
public final Class<?> originalType;
public final Class<?> targetType;
public final boolean explicitCast;

View File

@ -0,0 +1,511 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.painless;
public class BoxedCastTests extends ScriptTestCase {
public void testMethodCallByteToBoxedCasts() {
assertEquals(0, exec("byte u = 1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("byte u = 1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Byte u = Byte.valueOf((byte)1); Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); Double b = Double.valueOf((double)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("byte u = 1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("byte u = 1; def b = Double.valueOf((double)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); def b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Byte u = Byte.valueOf((byte)1); def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Byte u = Byte.valueOf((byte)1); def b = Double.valueOf((double)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (byte)1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (byte)1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (byte)1; def b = Double.valueOf((double)1); b.compareTo(u);"));
}
public void testMethodCallShortToBoxedCasts() {
expectScriptThrows(ClassCastException.class,
() -> exec("short u = 1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("short u = 1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Short u = Short.valueOf((short)1); Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Short u = Short.valueOf((short)1); Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("short u = 1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("short u = 1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("short u = 1; def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Short u = Short.valueOf((short)1); def b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Short u = Short.valueOf((short)1); def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Short u = Short.valueOf((short)1); def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (short)1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (short)1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (short)1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (short)1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (short)1; def b = Double.valueOf((double)1); b.compareTo(u);"));
}
public void testMethodCallCharacterToBoxedCasts() {
expectScriptThrows(ClassCastException.class,
() -> exec("char u = 1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("char u = 1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Character u = Character.valueOf((char)1); Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Character u = Character.valueOf((char)1); Short b = Short.valueOf((short)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("char u = 1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("char u = 1; def b = Short.valueOf((short)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("char u = 1; def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Character u = Character.valueOf((char)1); def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Character u = Character.valueOf((char)1); def b = Short.valueOf((short)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Character u = Character.valueOf((char)1); def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (char)1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (char)1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (char)1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (char)1; def b = Short.valueOf((short)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (char)1; def b = Double.valueOf((double)1); b.compareTo(u);"));
}
public void testMethodCallIntegerToBoxedCasts() {
expectScriptThrows(ClassCastException.class,
() -> exec("int u = 1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("int u = 1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("int u = 1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Integer u = Integer.valueOf((int)1); Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Integer u = Integer.valueOf((int)1); Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Integer u = Integer.valueOf((int)1); Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("int u = 1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("int u = 1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("int u = 1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("int u = 1; def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Integer u = Integer.valueOf((int)1); def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Integer u = Integer.valueOf((int)1); def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Integer u = Integer.valueOf((int)1); def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Integer u = Integer.valueOf((int)1); def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (int)1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (int)1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (int)1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (int)1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (int)1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (int)1; def b = Character.valueOf((char)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (int)1; def b = Double.valueOf((double)1); b.compareTo(u);"));
}
public void testMethodCallLongToBoxedCasts() {
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("long u = 1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("long u = 1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("long u = 1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Long u = Long.valueOf((long)1); Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Long u = Long.valueOf((long)1); Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Long u = Long.valueOf((long)1); Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("long u = 1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("long u = 1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("long u = 1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("long u = 1; def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Long u = Long.valueOf((long)1); def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("Long u = Long.valueOf((long)1); def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Long u = Long.valueOf((long)1); def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Long u = Long.valueOf((long)1); def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (long)1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (long)1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (long)1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (long)1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (long)1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (long)1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (long)1; def b = Double.valueOf((double)1); b.compareTo(u);"));
}
public void testMethodCallFloatToBoxedCasts() {
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("float u = 1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("float u = 1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Float u = Float.valueOf((float)1); Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Float u = Float.valueOf((float)1); Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("float u = 1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("float u = 1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("float u = 1; def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); def b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Float u = Float.valueOf((float)1); def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("Float u = Float.valueOf((float)1); def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Float u = Float.valueOf((float)1); def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (float)1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (float)1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (float)1; def b = Long.valueOf((long)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (float)1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (float)1; def b = Double.valueOf((double)1); b.compareTo(u);"));
}
public void testMethodCallDoubleToBoxedCasts() {
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("double u = 1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); Long b = Long.valueOf((long)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Double u = Double.valueOf((double)1); Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; def b = Long.valueOf((long)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("double u = 1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("double u = 1; def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); def b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); def b = Long.valueOf((long)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("Double u = Double.valueOf((double)1); def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("Double u = Double.valueOf((double)1); def b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; Byte b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; Short b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; Character b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; Integer b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; Long b = Long.valueOf((long)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; Float b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (double)1; Double b = Double.valueOf((double)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; def b = Byte.valueOf((byte)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; def b = Short.valueOf((short)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; def b = Character.valueOf((char)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; def b = Integer.valueOf((int)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; def b = Long.valueOf((long)1); b.compareTo(u);"));
expectScriptThrows(ClassCastException.class,
() -> exec("def u = (double)1; def b = Float.valueOf((float)1); b.compareTo(u);"));
assertEquals(0, exec("def u = (double)1; def b = Double.valueOf((double)1); b.compareTo(u);"));
}
}