-
Bug
-
Resolution: Duplicate
-
P2
-
7
-
generic
-
generic
Please see the minimized test below to reproduce the issue.
Minimized test:
===============
$ cat test.java
import java.lang.invoke.MethodType;
import static java.lang.invoke.MethodType.*;
import java.util.List;
import java.util.ArrayList;
public class test {
private final static Class[] RETURN_TYPES = {
void.class, int.class
};
private final static Class[] PARAM_TYPES = {
int.class, Void.class, Integer.class
};
public static void main(String[] args) {
for (int i = 0; i < RETURN_TYPES.length; i++) {
Class rtype = RETURN_TYPES[i];
boolean hasWraps = isWrapperType(rtype);
List params = new ArrayList();
for (Class ptype : PARAM_TYPES) {
params.add(ptype);
hasWraps |= isWrapperType(ptype);
MethodType mt = methodType(rtype, params);
try {
if (isWrapperType(rtype) != mt.hasWrappers()) {
System.out.println("hasWrappers() failed for method type "
+ mt + ": expected \"" + isWrapperType(rtype) + "\", "
+ "was given \"" + mt.hasWrappers() + "\"");
}
} catch (IllegalArgumentException iae) {
System.out.println("IllegalArgumentException was thrown "
+ "in hasWrappers() for method type " + mt);
}
}
}
}
private static boolean isWrapperType(final Class cl) {
if (cl.equals(Void.class) || cl.equals(Boolean.class)
|| cl.equals(Byte.class) || cl.equals(Character.class)
|| cl.equals(Short.class) || cl.equals(Integer.class)
|| cl.equals(Long.class) || cl.equals(Float.class)
|| cl.equals(Double.class)) {
return true;
}
return false;
}
}
$ javac test.java
Note: test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
$ java -showversion -verify -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic test
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b136)
Java HotSpot(TM) Server VM (build 21.0-b06, mixed mode)
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void)void
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void,Integer)void
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void)int
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void,Integer)int
Minimized test:
===============
$ cat test.java
import java.lang.invoke.MethodType;
import static java.lang.invoke.MethodType.*;
import java.util.List;
import java.util.ArrayList;
public class test {
private final static Class[] RETURN_TYPES = {
void.class, int.class
};
private final static Class[] PARAM_TYPES = {
int.class, Void.class, Integer.class
};
public static void main(String[] args) {
for (int i = 0; i < RETURN_TYPES.length; i++) {
Class rtype = RETURN_TYPES[i];
boolean hasWraps = isWrapperType(rtype);
List params = new ArrayList();
for (Class ptype : PARAM_TYPES) {
params.add(ptype);
hasWraps |= isWrapperType(ptype);
MethodType mt = methodType(rtype, params);
try {
if (isWrapperType(rtype) != mt.hasWrappers()) {
System.out.println("hasWrappers() failed for method type "
+ mt + ": expected \"" + isWrapperType(rtype) + "\", "
+ "was given \"" + mt.hasWrappers() + "\"");
}
} catch (IllegalArgumentException iae) {
System.out.println("IllegalArgumentException was thrown "
+ "in hasWrappers() for method type " + mt);
}
}
}
}
private static boolean isWrapperType(final Class cl) {
if (cl.equals(Void.class) || cl.equals(Boolean.class)
|| cl.equals(Byte.class) || cl.equals(Character.class)
|| cl.equals(Short.class) || cl.equals(Integer.class)
|| cl.equals(Long.class) || cl.equals(Float.class)
|| cl.equals(Double.class)) {
return true;
}
return false;
}
}
$ javac test.java
Note: test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
$ java -showversion -verify -XX:+UnlockExperimentalVMOptions -XX:+EnableInvokeDynamic test
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b136)
Java HotSpot(TM) Server VM (build 21.0-b06, mixed mode)
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void)void
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void,Integer)void
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void)int
IllegalArgumentException was thrown in hasWrappers() for method type (int,Void,Integer)int
- duplicates
-
JDK-7044892 JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
- Closed
- relates to
-
JDK-7034316 MethodType.hasWrappers() returns 'true' for method types like '()Comparable' or '()Deprecated'
- Closed
-
JDK-7032323 code changes for JSR 292 EG adjustments to API, through Public Review
- Closed