@@ -9,9 +9,9 @@ namespace Xamarin.Android.Tools.Bytecode
99 // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.16.1
1010 public abstract class AnnotationElementValue
1111 {
12- public virtual string ToEncodedString ( ) => ToString ( ) ;
12+ public virtual string ? ToEncodedString ( ) => ToString ( ) ;
1313
14- public static AnnotationElementValue Create ( ConstantPool constantPool , Stream stream )
14+ public static AnnotationElementValue ? Create ( ConstantPool constantPool , Stream stream )
1515 {
1616 var tag = stream . ReadNetworkByte ( ) ;
1717
@@ -38,8 +38,12 @@ public static AnnotationElementValue Create (ConstantPool constantPool, Stream s
3838
3939 var values = new List < AnnotationElementValue > ( ) ;
4040
41- for ( var i = 0 ; i < numValues ; i ++ )
42- values . Add ( Create ( constantPool , stream ) ) ;
41+ for ( var i = 0 ; i < numValues ; i ++ ) {
42+ var v = Create ( constantPool , stream ) ;
43+ if ( v == null )
44+ continue ;
45+ values . Add ( v ) ;
46+ }
4347
4448 return new AnnotationElementArray { Values = values . ToArray ( ) } ;
4549 }
@@ -79,49 +83,53 @@ public static AnnotationElementValue Create (ConstantPool constantPool, Stream s
7983
8084 public class AnnotationElementEnum : AnnotationElementValue
8185 {
82- public string TypeName { get ; set ; }
83- public string ConstantName { get ; set ; }
86+ public string ? TypeName { get ; set ; }
87+ public string ? ConstantName { get ; set ; }
8488
8589 public override string ToString ( ) => $ "Enum({ TypeName } .{ ConstantName } )";
8690 }
8791
8892 public class AnnotationElementClassInfo : AnnotationElementValue
8993 {
90- public string ClassInfo { get ; set ; }
94+ public string ? ClassInfo { get ; set ; }
9195
92- public override string ToString ( ) => ClassInfo ;
96+ public override string ? ToString ( ) => ClassInfo ;
9397 }
9498
9599 public class AnnotationElementAnnotation : AnnotationElementValue
96100 {
97- public Annotation Annotation { get ; set ; }
101+ public Annotation ? Annotation { get ; set ; }
98102
99- public override string ToString ( ) => Annotation . ToString ( ) ;
103+ public override string ? ToString ( ) => Annotation ? . ToString ( ) ;
100104 }
101105
102106 public class AnnotationElementArray : AnnotationElementValue
103107 {
104- public AnnotationElementValue [ ] Values { get ; set ; }
108+ public AnnotationElementValue [ ] ? Values { get ; set ; }
105109
106- public override string ToString ( ) => $ "[{ string . Join ( ", " , Values . Select ( v => v . ToString ( ) ) ) } ]";
110+ public override string ToString ( ) => Values == null
111+ ? "[]"
112+ : $ "[{ string . Join ( ", " , Values . Select ( v => v . ToString ( ) ) ) } ]";
107113
108- public override string ToEncodedString ( ) => $ "[{ string . Join ( ", " , Values . Select ( v => v . ToEncodedString ( ) ) ) } ]";
114+ public override string ? ToEncodedString ( ) => Values == null
115+ ? "[]"
116+ : $ "[{ string . Join ( ", " , Values . Select ( v => v . ToEncodedString ( ) ) ) } ]";
109117 }
110118
111119 public class AnnotationElementConstant : AnnotationElementValue
112120 {
113- public string Value { get ; set ; }
121+ public string ? Value { get ; set ; }
114122
115- public override string ToString ( ) => Value ;
123+ public override string ? ToString ( ) => Value ;
116124 }
117125
118126 public class AnnotationStringElementConstant : AnnotationElementConstant
119127 {
120128 public override string ToString ( ) => $ "\" { Value } \" ";
121129
122- public override string ToEncodedString ( )
130+ public override string ? ToEncodedString ( )
123131 {
124- return $ "\" { Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( Value ) ) } \" ";
132+ return $ "\" { Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( Value ?? "" ) ) } \" ";
125133 }
126134 }
127135}
0 commit comments