#188 parse Java @interface defaults

open
nobody
None
5
2014-02-25
2007-08-19
Elliott Hughes
No

we fall over on this:

public @interface i {
String n() default "ninjas; monkeys!";
String m();
}

producing a bogus unprintable tag containing the single character 0xd3, which is used by fileGetc to represent string constants. (which in itself is a bug, because 0xd3 could be part of an identifier.)

the easy part of the fix is something like this:

@@ -2019,6 +2019,10 @@
c = skipToNonWhite ();
}
} while (c == '.' || c == ',');
+ } else if (token->keyword == KEYWORD_DEFAULT) {
+ c = skipToNonWhite ();
+ readIdentifier (token, c);
+ c = skipToNonWhite ();
}
}
cppUngetc (c);

but the readIdentifier is wrong, because the default is an expression, and needn't be a single identifier.

Discussion

  • Aviv Eyal
    Aviv Eyal
    2014-02-25

    This is a simpler example that produces wrong output:

    public @interface Sample {
        int abc() default 1;
    }
    

    produces the symbol d instead of abc.