I want to add/replace the SourceFile attribute in a compiled Java .class file. I have not noticed any obscure command-line options to the Java compiler to override the default value of SourceFile. Neither have I seen anything in the Java reflection API that would help me. Skim reading chapter 4 of the JVM specification indicates I could spend a few weeks writing a .class file parser/modifier to do the work. Before I invest the effort to write such a parser/modifier, I want to check if I am missing something. Is there anything in the standard JDK to help with adding/replacing the SourceFile attribute?
For anyone wondering why I would want to mess with the SourceFile attribute... I have a command-line tool that preprocesses a "Java enhanced with some syntactic sugar" file into Java syntax. The file-name extension for this type of file is .bi. Thus, the preprocessor converts Foo.bi into Foo.java. In addition, there is line-number correspondence between Foo.bi and Foo.java, so if a runtime error occurs on, say, line 42 of Foo.java, then the bug should really be fixed on line 42 of Foo.bi (and then run the preprocessor and compile the updated Foo.java file). To facilitate this, I would like the stack trace of the error to indicate Foo.bi rather than Foo.java, and my experiments suggest this can be achieved by ensuring the Foo.class file has a SourceFile attribute with a value of Foo.bi.