Skip to content
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

Merged
merged 5 commits into from
Feb 27, 2024

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Jan 29, 2024

Attempt to unify all of the Exception flows on XmlConfiguration to always report the location of the XmlConfiguration resource (if able to).

Fixes: #11270

finally
{
if (parser instanceof Closeable)
((Closeable)parser).close();
if (parser instanceof Closeable closable)
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new XmlConfigurationException("Bad Xml Config in " + this, t);
throw new XmlConfigurationException("Bad Jetty XML configuration in " + this, t);

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@joakime joakime requested a review from sbordet February 13, 2024 16:30
joakime and others added 2 commits February 23, 2024 14:42
Cleaned up code in toString().

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@sbordet sbordet merged commit 2803f5a into jetty-12.0.x Feb 27, 2024
2 of 4 checks passed
@sbordet sbordet deleted the fix/12.0.x/xmlconfig-error-paths branch February 27, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: ✅ Done
2 participants