-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
Affects Version/s: repo-valhalla
-
Component/s: tools
The issues can be seen after compiling this Java source code:
import jdk.internal.vm.annotation.NullRestricted;
import jdk.internal.vm.annotation.Strict;
public class NRTest {
static value class Value {
int i = 0;
}
@Strict
@NullRestricted
Value v = new Value();
public static void main(String[] args) {
var t = new NRTest();
}
}
When disassembling the produced class file, the information related to the field v is:
NRTest$Value v;
descriptor: LNRTest$Value;
flags: (0x0800) ACC_STRICT_INIT
RuntimeVisibleAnnotations:
0: #18()
jdk.internal.vm.annotation.NullRestricted
RuntimeInvisibleAnnotations:
0: #20()
jdk.internal.vm.annotation.Strict
Javac correctly sets the ACC_STRICT_INIT flag in the field's access flags.
However, javac also puts jdk.internal.vm.annotation.Strict in the set of runtime annotations of the field. This is redundant with the ACC_STRICT_INIT flag, and it is not consistent with the definition of the Strict annotation which is declared as having a SOURCE policy retention:
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface Strict {
}
import jdk.internal.vm.annotation.NullRestricted;
import jdk.internal.vm.annotation.Strict;
public class NRTest {
static value class Value {
int i = 0;
}
@Strict
@NullRestricted
Value v = new Value();
public static void main(String[] args) {
var t = new NRTest();
}
}
When disassembling the produced class file, the information related to the field v is:
NRTest$Value v;
descriptor: LNRTest$Value;
flags: (0x0800) ACC_STRICT_INIT
RuntimeVisibleAnnotations:
0: #18()
jdk.internal.vm.annotation.NullRestricted
RuntimeInvisibleAnnotations:
0: #20()
jdk.internal.vm.annotation.Strict
Javac correctly sets the ACC_STRICT_INIT flag in the field's access flags.
However, javac also puts jdk.internal.vm.annotation.Strict in the set of runtime annotations of the field. This is redundant with the ACC_STRICT_INIT flag, and it is not consistent with the definition of the Strict annotation which is declared as having a SOURCE policy retention:
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface Strict {
}
- relates to
-
JDK-8373942 [lworld] Javac should not generate a loadable descriptor for null restricted value fields
-
- Open
-
- links to
-
Commit(lworld)
openjdk/valhalla/20f2dbfa
-
Review(lworld)
openjdk/valhalla/1820