{"record":{"id":"0dfdf40f2992ba24","repo":"pxb1988/dex2jar","slug":"recognitionexception-on-invalid-annotation-element-0dfdf4","errorCode":null,"errorMessage":"RecognitionException on invalid annotation element keyword (expected 's')","messagePattern":"RecognitionException on invalid annotation element keyword \\(expected 's'\\)","errorType":"validation","errorClass":"RecognitionException","httpStatus":null,"severity":"error","filePath":"d2j-jasmin/src/main/antlr3/com/googlecode/d2j/jasmin/Jasmin.g","lineNumber":1043,"sourceCode":"              \t    | '.doub_kind' a=STRING b=(INT|LONG)  {$nn=unEscapeString($a.text); $v=parseDouble($b.text);}\r\n              \t    | '.str_kind' a=STRING b=STRING       {$nn=unEscapeString($a.text); $v=unEscapeString($b.text);}\r\n              \t    | '.enum_kind' a=STRING b=STRING      {$nn=unEscapeString($a.text); String on[]=parseOwnerAndName($b.text);$v=new String[]{on[0],on[1]};}\r\n              \t    | '.cls_kind' a=STRING b=STRING       {$nn=unEscapeString($a.text); $v=Type.getType(unEscapeString($b.text));}\r\n              \t    | '.arr_kind' a=STRING {List<Object> array=new ArrayList<>();} (t=sAnnotationElementSoot{array.add($t.v);})* '.end'  '.arr_elem'   {$nn=unEscapeString($a.text); $v=array;}\r\n              \t    | '.ann_kind' a=STRING q=sSubannotationSoot '.end' '.annot_elem'     {$nn=unEscapeString($a.text); $v=$q.v;})\r\n\t;\r\n\r\nsSubannotationSoot  returns[AnnotationNode v]\r\n\t:\t'.annotation' a=STRING   { $v=new AnnotationNode(unEscapeString($a.text)); }\r\n\t     (t=sAnnotationElementSoot {$v.visit($t.nn,$t.v);} )*\r\n\t    '.end' '.annotation'\r\n\t;\r\nsAnnotationElement @init{List<Object> array = new ArrayList<Object>(); AnnotationNode _t= currentAnnotationVisitor;}\r\n    :   a=sId (\r\n             xid=ID { if(!\"e\".contains($xid.text)){ throw new RecognitionException(input);} }  c=OBJECT_TYPE '=' b=sWord {  _t.visit($a.text,new String[]{$c.text,$b.text}); }\r\n           | AT b2=OBJECT_TYPE '=' {  currentAnnotationVisitor=new AnnotationNode($b2.text);} sSubannotation  { _t.visit($a.text,currentAnnotationVisitor); }\r\n           | xid=ID { if(!\"c\".contains($xid.text)){ throw new RecognitionException(input);} } '=' b1=sClassDesc { currentAnnotationVisitor.visit($a.text,Type.getType($b1.text)); }\r\n           | xid=ID { if(!\"s\".contains($xid.text)){ throw new RecognitionException(input);} } '=' b3=STRING      { currentAnnotationVisitor.visit($a.text,unEscapeString($b3.text)); }\r\n           | UP_B  '=' b4=INT  { currentAnnotationVisitor.visit($a.text,(byte)parseInt($b4.text)); }\r\n           | UP_Z  '=' b5=INT  { currentAnnotationVisitor.visit($a.text,0!=parseInt($b5.text)); }\r\n           | UP_S  '=' b6=INT   { currentAnnotationVisitor.visit($a.text,(short)parseInt($b6.text)); }\r\n           | UP_C  '=' b7=INT   { currentAnnotationVisitor.visit($a.text,(char)parseInt($b7.text)); }\r\n           | UP_I  '=' b8=INT   { currentAnnotationVisitor.visit($a.text,parseInt($b8.text)); }\r\n           | UP_J  '=' b9=(INT|LONG)  { currentAnnotationVisitor.visit($a.text,parseLong($b9.text)); }\r\n           | UP_F  '=' b10=(INT|FLOAT|DOUBLE)  { currentAnnotationVisitor.visit($a.text,parseFloat($b10.text)); }\r\n           | UP_D  '=' b11=(INT|FLOAT|DOUBLE)   { currentAnnotationVisitor.visit($a.text,parseDouble($b11.text)); }\r\n           | ARRAY_B '='  (b12=INT {array.add((byte)parseInt($b12.text));} )+    { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_Z '='  (b13=INT {array.add(0!=parseInt($b13.text));} )+       { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_S '='  (b14=INT {array.add((short)parseInt($b14.text));} )+   { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_C '='  (b15=INT {array.add((char)parseInt($b15.text));} )+    { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_I '='  (b16=INT {array.add(parseInt($b16.text));} )+          { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_J '='  (b17=(INT|LONG) {array.add(parseLong($b17.text));} )+  { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_F '='  (b18=(INT|FLOAT|DOUBLE) {array.add(parseFloat($b18.text));} )+  { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_D '='  (b19=(INT|DOUBLE) {array.add(parseDouble($b19.text));} )+       { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_LOW_E c=OBJECT_TYPE '='  ((b1=sWord{  array.add(new String[]{$c.text,unEscape($b1.text)}); }|b2=STRING{  array.add(new String[]{$c.text,unEscapeString($b2.text)}); }|b3=DSTRING{  array.add(new String[]{$c.text,unEscapeString($b3.text)}); })  )+  { currentAnnotationVisitor.visit($a.text,array); }\r\n           | ARRAY_AND b20=OBJECT_TYPE '=' ARRAY_AT '='  ({currentAnnotationVisitor=new AnnotationNode($b20.text);} sSubannotation{ array.add(currentAnnotationVisitor); })+ { currentAnnotationVisitor.visit($a.text,array); }\r","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/d2j-jasmin/src/main/antlr3/com/googlecode/d2j/jasmin/Jasmin.g#L1025-L1061","documentation":"The sAnnotationElement string alternative requires the keyword 's' followed by '=' and a STRING, storing the element via unEscapeString. The guard if(!\"s\".contains($xid.text)){ throw new RecognitionException(input); } throws when the ID before '=' is not exactly 's' (Jasmin.g:1043). Like the 'e'/'c' variants, the RecognitionException is used for grammar backtracking; surfacing it to the user means none of the element alternatives accepted the keyword.","triggerScenarios":"An annotation element in a Jasmin .j file where a string value follows 'name = ' but the keyword ID is not 's', e.g. 'strvalue = \"hello\"' or 'string = \"hello\"' inside a '.annotation' block assembled with d2j-jasmin.","commonSituations":"Files written for other Jasmin dialects that spell the string element differently; manual edits that renamed the element keyword; case mistakes like 'S' (which the grammar treats as the short primitive token, so 'S = \"x\"' fails here too since the guard expects lowercase 's' followed by a STRING, not the UP_S token path which requires an INT).","solutions":["Use the exact keyword 's' for string annotation elements: 's = \"text\"' inside the .annotation block","Lowercase the keyword (the contains check is case-sensitive against \"s\")","If the value is not a string, pick the correct alternative keyword: 'e' enum, 'c' class, B/Z/S/C/I/J tokens for primitives","Re-dump the method from the dex with a d2j-compatible tool so annotation elements are emitted in the accepted syntax"],"exampleFix":"// before\nstring = \"hello\"\n\n// after\ns = \"hello\"","handlingStrategy":"validation","validationCode":"// verify string annotation elements are written with keyword 's'\nPattern strElem = Pattern.compile(\"\\\\s*([A-Za-z_][\\\\w$]*)\\\\s*=\\\\s*\\\"([^\\\"]*)\\\"\\\\s*$\");\nMatcher m = strElem.matcher(jasminSource);\nwhile (m.find()) {\n    if (!m.group(1).equals(\"s\")) {\n        throw new IllegalArgumentException(\"string annotation element must use keyword 's', found '\" + m.group(1) + \"'\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    new Jasmin(new StringReader(jasminSource)).parse();\n} catch (RecognitionException e) {\n    throw new JasminSyntaxException(\"String annotation elements must be 's = \\\"...\\\"'\", e);\n}","preventionTips":["Write string elements exactly as s = \"value\" in .annotation blocks","Escape embedded quotes/unicode through unEscapeString-compatible syntax","Check case sensitivity: 'S' routes to the short primitive alternative and requires an INT, so it will not accept a STRING","Prefer generating annotations from bytecode dumps over manual editing"],"tags":["parser","grammar","jasmin","annotation"],"backgroundTag":"invalid-enum-value","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}