antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
956 stars 231 forks source link

The code and source jars have line number mismatches, and no warning for a template name/filename mismatch #270

Open rwperrott opened 4 years ago

rwperrott commented 4 years ago

When I try and debug a NullPointerException (!) in ST4-4.0.8.jar, for a 'missing' .st file, the byte-code line number and source jar line numbers don't match, so I have to hunt for the method and guess where inside inside it the exception occurred, which is stupid and annoying, this frustration appears to cover the whole of my stack trace inside the Jar, hmm!

The NullPointerException was caused by the template name being different from the .st filename, but all I got was a very unhelpful NullPointerException because it couldn't find the template name in the templates map in the STGroup class.

Clashsoft commented 4 years ago

Did you try the latest version 4.3.1?

rwperrott commented 4 years ago

Yes, that's what I'm actually got set in my pom.xml, it looks like IDEA displayed stale dependency data, for my Maven import, and a re-import fixed that; I may retry debugging later, to verify the 1st issue. My builds were Maven based, so the 2nd issue probably still exists.

rwperrott commented 4 years ago

Adding to this, using 4.3.1:

parrt commented 4 years ago

Thanks for the report, @rwperrott !!

rwperrott commented 4 years ago

I don't expect the 2nd issue above to be addressed soon, so investigated more and made a workaround, which I expect to drop later.

This hack successfully converts relative line numbers to absolute ones for STGroupFile, including imports, via STGroup::getImportedGroups(), and should work with STGroupString too. I suspect that supporting STGroupDir will be a pain.

rwperrott commented 4 years ago

I suggest that CompiledST objects should carry an absolute start line number and Misc.getLineCharPosition sets line from a start line parameter, not unreliable 1, and that callers, like STRuntimeMessage, are updated to pass in the absolute start line number.