antlr / stringtemplate4

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

STGroupFile constructor suppresses exceptions #204

Closed bobflannigon closed 6 years ago

bobflannigon commented 6 years ago

Passing in a null URL into this constructor does not fail: STGroupFile(URL url, String encoding, delimiterStartChar, char delimiterStopChar)

This constructor: STGroupFile(String fileName, char delimiterStartChar, char delimiterStopChar) will throw a MalformedURLException if the file cannot be found.

Inconsistent behaviour aside, this constructor allows us to instantiate the STGroupFile with a null URL, meaning that we can call load(), mark the alreadyLoaded flag as true, load will fail and the STGroupFile Object is in a state from which we can never recover or easily find out what went wrong.

Required Fix:

  1. Fix the constructors so they throw the same exceptions (in particular MalformedURLException, preferably IllegalArgumentException for nulls).

Nice-to-have:

  1. Fix load so that if loading fails the alreadyLoaded flag is reset, and throw an exception from this method that isn't just a NullPointerException.