{"record":{"id":"95dd062c713c5557","repo":"pxb1988/dex2jar","slug":"recognitionexception-on-invalid-annotation-element","errorCode":null,"errorMessage":"RecognitionException on invalid annotation element keyword (expected 'e')","messagePattern":"RecognitionException on invalid annotation element keyword \\(expected 'e'\\)","errorType":"validation","errorClass":"RecognitionException","httpStatus":null,"severity":"error","filePath":"d2j-jasmin/src/main/antlr3/com/googlecode/d2j/jasmin/Jasmin.g","lineNumber":1040,"sourceCode":"              \t    | '.int_kind' a=STRING b=INT          {$nn=unEscapeString($a.text); $v=parseInt($b.text);}\r\n              \t    | '.long_kind' a=STRING b=(INT|LONG)  {$nn=unEscapeString($a.text); $v=parseLong($b.text);}\r\n              \t    | '.float_kind' a=STRING b=INT        {$nn=unEscapeString($a.text); $v=parseFloat($b.text);}\r\n              \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","sourceCodeStart":1022,"sourceCodeEnd":1058,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/d2j-jasmin/src/main/antlr3/com/googlecode/d2j/jasmin/Jasmin.g#L1022-L1058","documentation":"In Jasmin.g the sAnnotationElement rule accepts several alternatives that all start with an ID token; each alternative guards the ID text with a check like if(!\"e\".contains($xid.text)){ throw new RecognitionException(input); }. This error fires when the parser matched the enum-element alternative (the one expecting the keyword 'e' followed by OBJECT_TYPE '=' sWord) but the ID text is not 'e', so a RecognitionException is thrown to force the parser to try the other alternatives. It is a grammar-level backtracking mechanism rather than a normal runtime error, but when no alternative matches, the user sees it as a parse failure.","triggerScenarios":"Assembling a Jasmin (.j) file whose .annotation element uses an enum element but the element keyword token before OBJECT_TYPE is not exactly 'e', e.g. writing 'enumvalue = LSomeEnum;.FIELD SomeValue' or an empty/mistyped keyword inside a '.annotation' block fed to the Jasmin assembler (AsmV3 jasmin assembler, sAnnotationElement rule at Jasmin.g:1040).","commonSituations":"Hand-written or Soot-produced Jasmin that uses an annotation element keyword other than the single letters this grammar accepts (e/c/s/B/Z/S/C/I/J); typos in the element kind; Jasmin dialects (e.g. original Soot jasmin syntax) that spell the enum element differently than d2j-jasmin expects.","solutions":["Fix the .j file so the enum annotation element uses the exact keyword 'e' before the type and '=' (e.g. 'e = Lcom/Type;.FIELD V')","Check which alternative the element actually belongs to and use the matching keyword: 'c' for class desc, 's' for string, 'B/Z/S/C/I/J' tokens for primitives","If the file comes from another tool (Soot/dx), re-emit the annotation with d2j-jasmin's accepted syntax or convert the source with dexdump/baksmali instead","If you control the grammar, replace the ID-plus-'contains' guard alternatives with explicit token keywords so the error points at the real offending token"],"exampleFix":"// before (in .j file inside .annotation)\nkind = LMyEnum;.VALUE X\n\n// after\n e = LMyEnum;.VALUE X","handlingStrategy":"validation","validationCode":"// before invoking the assembler, scan .annotation elements in the .j text\nPattern enumElem = Pattern.compile(\"^\\\\s*(?!e\\\\s*=)[A-Za-z_][A-Za-z0-9_$]*\\\\s*=\\\\s*L[A-Za-z0-9_$/;.;-]+\\\\.\\\\S+\\\\s+\\\\S+$\", Pattern.MULTILINE);\nMatcher m = enumElem.matcher(jasminSource);\nif (m.find()) {\n    throw new IllegalArgumentException(\"line \" + countLine(jasminSource, m.start()) +\n        \": enum annotation element must use keyword 'e', found '\" + m.group(1) + \"'\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    new Jasmin(new StringReader(jasminSource)).parse();\n} catch (RecognitionException e) {\n    throw new JasminSyntaxException(\"Unsupported annotation element keyword: use 'e', 'c', 's', or primitive tokens B/Z/S/C/I/J\", e);\n}","preventionTips":["Use only the single-letter element keywords d2j-jasmin accepts: e, c, s, and tokens B/Z/S/C/I/J","Generate .j files with a d2j-compatible dumper rather than hand-writing annotation blocks","Lint .annotation blocks with a regex for keyword '= value' shape before assembling","Keep letter case exact: guards compare lowercase 'e'/'c'/'s'"],"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"}