{"record":{"id":"e7c1ecc15990b1d8","repo":"pxb1988/dex2jar","slug":"recognitionexception-on-invalid-annotation-element-e7c1ec","errorCode":null,"errorMessage":"RecognitionException on invalid annotation element keyword (expected 'c')","messagePattern":"RecognitionException on invalid annotation element keyword \\(expected 'c'\\)","errorType":"validation","errorClass":"RecognitionException","httpStatus":null,"severity":"error","filePath":"d2j-jasmin/src/main/antlr3/com/googlecode/d2j/jasmin/Jasmin.g","lineNumber":1042,"sourceCode":"              \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\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","sourceCodeStart":1024,"sourceCodeEnd":1060,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/d2j-jasmin/src/main/antlr3/com/googlecode/d2j/jasmin/Jasmin.g#L1024-L1060","documentation":"Same sAnnotationElement rule as error 130: this alternative expects the keyword 'c' (a class-descriptor annotation element, parsed as sClassDesc and converted via Type.getType). When the ID token matched by xid is not 'c', the guard if(!\"c\".contains($xid.text)){ throw new RecognitionException(input); } throws at Jasmin.g:1042, signaling the parser to backtrack. If no other alternative matches the element either, the whole .annotation block fails to assemble.","triggerScenarios":"An annotation element in a Jasmin file that supplies a class descriptor after 'name = ' but whose keyword ID is not exactly 'c', e.g. 'value = Ljava/lang/Class;.TYPE' written as 'classvalue = Ljava/lang/Class;.TYPE' or with the keyword omitted, inside '.annotation' ... '.end annotation' passed to the d2j-jasmin assembler.","commonSituations":"Migrating Jasmin output from Soot or older assemblers whose annotation-element syntax used full words ('class', 'enum', 'string') instead of the single letters this grammar hard-codes; typos like 'C' vs 'c' (grammar is case-sensitive); copy-pasted annotation lines edited by hand.","solutions":["Write the class-type annotation element exactly as 'c = <classDesc>' e.g. 'c = Ljava/lang/Class;.class' in the .j file","Verify letter case: the guard compares against lowercase 'c', so 'C' will not match","If the element is really an enum/string/primitive, use the corresponding keyword ('e', 's', or the token B/Z/S/C/I/J) instead","Regenerate the Jasmin file from the original dex/jar with a d2j-compatible dumper rather than editing by hand"],"exampleFix":"// before\nclassvalue = Ljava/lang/Class;.TYPE\n\n// after\nc = Ljava/lang/Class;.TYPE","handlingStrategy":"validation","validationCode":"// validate class-descriptor annotation elements use keyword 'c'\nfor (String line : jasminLines) {\n    if (line.matches(\"\\\\s*[A-Za-z_][\\\\w$]*\\\\s*=\\\\s*L[^ ]*\\\\.[^ ]+\\\\s*$\") && !line.trim().startsWith(\"e \") && !line.matches(\"\\\\s*c\\\\s*=.*\")) {\n        throw new IllegalArgumentException(\"class annotation element must start with 'c = ': \" + line.trim());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Jasmin asm = new Jasmin(new FileReader(jasminFile));\n    asm.parse();\n} catch (RecognitionException | RuntimeException e) {\n    LOG.error(\"annotation element in {} rejected (expect keyword 'c' before class desc)\", jasminFile, e);\n    throw new JasminSyntaxException(\"Invalid class annotation element\", e);\n}","preventionTips":["Always prefix class-type annotation values with 'c = ' in .j files","Do not use 'C' or full words like 'class' — the grammar compares against lowercase \"c\"","Diff generated Jasmin against a known-good d2j dump when porting from Soot syntax","Parse files in CI with the assembler to catch syntax drift early"],"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"}