-
Notifications
You must be signed in to change notification settings - Fork 105
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
Formatting exception message #16
base: master
Are you sure you want to change the base?
Conversation
final Class<?> clazz = defineClass(transformedName, transformedClass, 0, transformedClass.length, codeSource); | ||
cachedClasses.put(transformedName, clazz); | ||
return clazz; | ||
if (transformedClass != null) { |
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.
Honestly I don't think there is anything wrong with skipping the null check here. If it is null then it throws an exception which is caught and logged below. Thus adding more detail to the stack trace. More details, the better. So I don't see a need for this protection.
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.
IMO it is worth checking it, as otherwise it will NPE when trying to save the transformed class (DEBUG_SAVE == true
), and when not debug saving, the exception it does print points to the classloader itself NPEing, not that it couldn't find the class source.
There's also zero point going through the transformer list with null bytes, unless you're expecting one of them might provide the data?!
} catch (Throwable e) { | ||
invalidClasses.add(name); | ||
if (DEBUG) { | ||
LogWrapper.log(Level.TRACE, e, "Exception encountered attempting classloading of %s", name); | ||
LogManager.getLogger("LaunchWrapper").log(Level.ERROR, "Exception encountered attempting classloading of %s", e); | ||
LogManager.getLogger("LaunchWrapper").log(Level.ERROR, String.format("Exception encountered attempting classloading of %s", name), e); |
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.
This however, is fine, cuz derp.
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.
Why not use the proper log4j way of doing things - basically replace %s
for {}
, no String#format(String)
needed.
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.
@jamierocks There does not appear to be an interface method that takes both a Throwable
and params.
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 believe that log4j knows to use the last parameter as a Throwable
when taking a series of other parameters; however, I cannot find a source.
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 write it this way:
LogManager.getLogger("LaunchWrapper").error("Exception encountered attempting classloading of {}", name, e);
Internally the logger creates a FormattedMessage
which can take a Throwable
as the last argument:
https://logging.apache.org/log4j/log4j-2.1/log4j-api/apidocs/org/apache/logging/log4j/message/FormattedMessage.html
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.
Tracing through it doesn't use that constructor from the varargs method, but it does appear poke was correct as it seems to scan it at org.apache.logging.log4j.message.ParameterizedMessage#parseArguments
Why, why this isn't merged?
|
I just fix two bugs I found during my experiments