-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #11270 - Improve XmlConfiguration reporting of Resource location during error #11345
Conversation
…n during error
…lconfig-error-paths
finally | ||
{ | ||
if (parser instanceof Closeable) | ||
((Closeable)parser).close(); | ||
if (parser instanceof Closeable closable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: closeable
*/ | ||
public XmlConfiguration(Resource resource) throws SAXException, IOException | ||
public XmlConfiguration(Resource resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm, this is now a breaking change, as user code that did try/catch (IOException)
will now get a compilation error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess I can leave those throws
declarations to not change the signature,
Doesn't matter if that they will never happen with the other changes in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -280,10 +277,14 @@ public XmlConfiguration(Resource resource, Map<String, Object> idMap, Map<String | |||
_idMap = idMap == null ? new HashMap<>() : idMap; | |||
_propertyMap = properties == null ? new HashMap<>() : properties; | |||
} | |||
catch (Throwable t) | |||
{ | |||
throw new XmlConfigurationException("Bad Xml Config in " + this, t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new XmlConfigurationException("Bad Xml Config in " + this, t); | |
throw new XmlConfigurationException("Bad Jetty XML configuration in " + this, t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -465,14 +466,14 @@ public Object configure() throws Exception | |||
} | |||
catch (NoSuchMethodException x) | |||
{ | |||
throw new IllegalStateException(String.format("No matching constructor %s in %s", oClass, _configuration)); | |||
throw new XmlConfigurationException("No matching constructor " + oClass); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would throw IllegalStateException
here as before, because A) in many other places you did not convert to throw XmlConfigurationException
(you converted just a couple), and it's caught and rethrown as XmlConfigurationException
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -429,7 +430,7 @@ public Object configure(Object obj) throws Exception | |||
if (oClass != null && !oClass.isInstance(obj)) | |||
{ | |||
String loaders = (oClass.getClassLoader() == obj.getClass().getClassLoader()) ? "" : "Object Class and type Class are from different loaders."; | |||
throw new IllegalArgumentException("Object of class '" + obj.getClass().getCanonicalName() + "' is not of type '" + oClass.getCanonicalName() + "'. " + loaders + " in " + _configuration); | |||
throw new XmlConfigurationException("Object of class '" + obj.getClass().getCanonicalName() + "' is not of type '" + oClass.getCanonicalName() + "'. " + loaders); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…lconfig-error-paths
Cleaned up code in toString(). Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Attempt to unify all of the Exception flows on
XmlConfiguration
to always report the location of theXmlConfiguration
resource (if able to).Fixes: #11270