42
42
import jdk .internal .classfile .impl .Util ;
43
43
import jdk .internal .javac .PreviewFeature ;
44
44
45
+ import static java .util .Objects .requireNonNull ;
46
+
45
47
/**
46
48
* Models an {@code element_value} structure, or a value of an element-value
47
49
* pair of an annotation, as defined in JVMS {@jvms 4.7.16.1}.
@@ -488,6 +490,8 @@ default ClassDesc classSymbol() {
488
490
*/
489
491
static OfEnum ofEnum (Utf8Entry className ,
490
492
Utf8Entry constantName ) {
493
+ requireNonNull (className );
494
+ requireNonNull (constantName );
491
495
return new AnnotationImpl .OfEnumImpl (className , constantName );
492
496
}
493
497
@@ -506,6 +510,7 @@ static OfEnum ofEnum(ClassDesc className, String constantName) {
506
510
* @param className the descriptor string of the class
507
511
*/
508
512
static OfClass ofClass (Utf8Entry className ) {
513
+ requireNonNull (className );
509
514
return new AnnotationImpl .OfClassImpl (className );
510
515
}
511
516
@@ -522,6 +527,7 @@ static OfClass ofClass(ClassDesc className) {
522
527
* @param value the string
523
528
*/
524
529
static OfString ofString (Utf8Entry value ) {
530
+ requireNonNull (value );
525
531
return new AnnotationImpl .OfStringImpl (value );
526
532
}
527
533
@@ -538,6 +544,7 @@ static OfString ofString(String value) {
538
544
* @param value the double value
539
545
*/
540
546
static OfDouble ofDouble (DoubleEntry value ) {
547
+ requireNonNull (value );
541
548
return new AnnotationImpl .OfDoubleImpl (value );
542
549
}
543
550
@@ -554,6 +561,7 @@ static OfDouble ofDouble(double value) {
554
561
* @param value the float value
555
562
*/
556
563
static OfFloat ofFloat (FloatEntry value ) {
564
+ requireNonNull (value );
557
565
return new AnnotationImpl .OfFloatImpl (value );
558
566
}
559
567
@@ -570,6 +578,7 @@ static OfFloat ofFloat(float value) {
570
578
* @param value the long value
571
579
*/
572
580
static OfLong ofLong (LongEntry value ) {
581
+ requireNonNull (value );
573
582
return new AnnotationImpl .OfLongImpl (value );
574
583
}
575
584
@@ -586,6 +595,7 @@ static OfLong ofLong(long value) {
586
595
* @param value the int value
587
596
*/
588
597
static OfInt ofInt (IntegerEntry value ) {
598
+ requireNonNull (value );
589
599
return new AnnotationImpl .OfIntImpl (value );
590
600
}
591
601
@@ -602,6 +612,7 @@ static OfInt ofInt(int value) {
602
612
* @param value the short value
603
613
*/
604
614
static OfShort ofShort (IntegerEntry value ) {
615
+ requireNonNull (value );
605
616
return new AnnotationImpl .OfShortImpl (value );
606
617
}
607
618
@@ -618,6 +629,7 @@ static OfShort ofShort(short value) {
618
629
* @param value the char value
619
630
*/
620
631
static OfChar ofChar (IntegerEntry value ) {
632
+ requireNonNull (value );
621
633
return new AnnotationImpl .OfCharImpl (value );
622
634
}
623
635
@@ -634,6 +646,7 @@ static OfChar ofChar(char value) {
634
646
* @param value the byte value
635
647
*/
636
648
static OfByte ofByte (IntegerEntry value ) {
649
+ requireNonNull (value );
637
650
return new AnnotationImpl .OfByteImpl (value );
638
651
}
639
652
@@ -650,6 +663,7 @@ static OfByte ofByte(byte value) {
650
663
* @param value the boolean value
651
664
*/
652
665
static OfBoolean ofBoolean (IntegerEntry value ) {
666
+ requireNonNull (value );
653
667
return new AnnotationImpl .OfBooleanImpl (value );
654
668
}
655
669
@@ -667,6 +681,7 @@ static OfBoolean ofBoolean(boolean value) {
667
681
* @param value the annotation
668
682
*/
669
683
static OfAnnotation ofAnnotation (Annotation value ) {
684
+ requireNonNull (value );
670
685
return new AnnotationImpl .OfAnnotationImpl (value );
671
686
}
672
687
@@ -784,6 +799,6 @@ static AnnotationValue of(Object value) {
784
799
} else if (value instanceof Enum <?> e ) {
785
800
return ofEnum (ClassDesc .ofDescriptor (e .getDeclaringClass ().descriptorString ()), e .name ());
786
801
}
787
- throw new IllegalArgumentException ("Illegal annotation constant value type " + (value == null ? null : value .getClass () ));
802
+ throw new IllegalArgumentException ("Illegal annotation constant value type " + requireNonNull (value ) .getClass ());
788
803
}
789
804
}
0 commit comments