-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
generic
-
generic
Taken basis in the class file format API - Assuming the following class, multiple type annotations are not placed correctly or are even refused to be compiled:
public class Sample {
void invocation_type_argument() {
var o1 = new @Annon(1) ArrayList<>(); // is NEW (0x44), as expected
var o2 = new ArrayList<@Annon(2) Object>(); // should be CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT (0x48), not NEW (0x44) (
var o3 = List.<@Annon(3) Object>of(); // is METHOD_INVOCATION_TYPE_ARGUMENT (0x49), as expected
}
void constructor_reference() {
Supplier<?> o1 = @Annon(1) ArrayList::new; // is CONSTRUCTOR_REFERENCE (0x45), as expected
Supplier<?> o2 = ArrayList<@Annon(2) Object>::new; // should be CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT (0x4A), not CONSTRUCTOR_REFERENCE (0x45)
}
/*void method_reference() {
Supplier<?> o1 = @Annon(1) List::of; // should compile and be METHOD_REFERENCE (0x46)
Supplier<?> o2 = List<@Annon(2) Object>::of; // should compile and be METHOD_REFERENCE_TYPE_ARGUMENT (0x4B)
}*/
@Target(ElementType.TYPE_USE)
@interface Annon {
int value();
}
}
1. In sample method "invocation_type_argument", the type annotations for o1 and o2 are both assigned to NEW, where the second should be placed to CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT. The same is done correctly for a METHOD_INVOCATION_TYPE_ARGUMENT as in o3.
2. In sample method "constructor_reference", the type annotation for o2 should be placed as CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, but both are placed as CONSTRUCTOR_REFERENCE.
3. The Java language specification forsees the possibility to annotated method references similarly to constructor references. Nevertheless, neither line of "method_reference" does compile whereas the first type annotation is expected on METHOD_REFERENCE, the second on METHOD_REFERENCE_TYPE_ARGUMENT.
This can be validated by passing the class through javap.
public class Sample {
void invocation_type_argument() {
var o1 = new @Annon(1) ArrayList<>(); // is NEW (0x44), as expected
var o2 = new ArrayList<@Annon(2) Object>(); // should be CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT (0x48), not NEW (0x44) (
var o3 = List.<@Annon(3) Object>of(); // is METHOD_INVOCATION_TYPE_ARGUMENT (0x49), as expected
}
void constructor_reference() {
Supplier<?> o1 = @Annon(1) ArrayList::new; // is CONSTRUCTOR_REFERENCE (0x45), as expected
Supplier<?> o2 = ArrayList<@Annon(2) Object>::new; // should be CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT (0x4A), not CONSTRUCTOR_REFERENCE (0x45)
}
/*void method_reference() {
Supplier<?> o1 = @Annon(1) List::of; // should compile and be METHOD_REFERENCE (0x46)
Supplier<?> o2 = List<@Annon(2) Object>::of; // should compile and be METHOD_REFERENCE_TYPE_ARGUMENT (0x4B)
}*/
@Target(ElementType.TYPE_USE)
@interface Annon {
int value();
}
}
1. In sample method "invocation_type_argument", the type annotations for o1 and o2 are both assigned to NEW, where the second should be placed to CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT. The same is done correctly for a METHOD_INVOCATION_TYPE_ARGUMENT as in o3.
2. In sample method "constructor_reference", the type annotation for o2 should be placed as CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, but both are placed as CONSTRUCTOR_REFERENCE.
3. The Java language specification forsees the possibility to annotated method references similarly to constructor references. Nevertheless, neither line of "method_reference" does compile whereas the first type annotation is expected on METHOD_REFERENCE, the second on METHOD_REFERENCE_TYPE_ARGUMENT.
This can be validated by passing the class through javap.