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
Provide more context information when unable to read input during instrumentation #527
Conversation
7e7c2c8
to
2fff4aa
Compare
@@ -114,7 +114,7 @@ protected String getCommonSuperClass(final String type1, | |||
return instrument(new ClassReader(buffer)); | |||
} | |||
} catch (final RuntimeException e) { | |||
throw instrumentError(name, e); | |||
throw instrumentError("class " + 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.
@Godin Why do we need "class" prefix here? Typically the name will be the file name (Example.class) anyways. In case of classes nested in archives this will lead to locations like "archive.jar@class Example.zip". I would prefer not adding a prefix like in Analyzer
.
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.
@marchof Here is a story: at first I also wanted to remove word "class", then realized that Instrumenter
is used by CoverageTransformer
and CoverageTransformerTest
expects word "class", where BTW name
is not a name of file but a name of class and so without extension .class
. After that instead of removal I pulled this word up from instrumentError
into existing places of usage instrumentError
, preserving existing error messages. And then added new usages of instrumentError
without word "class" into places where name
does not refer to a class.
Also "archive.jar@class something" is impossible - word "class" can't appear in the middle, because its addition happens at the very end when name
is already fully constructed, and its addition happens only in places where we know that name
refers to a class.
And so alternatively there are two other options - move addition of prefix "class" into CoverageTransformer
or completely remove it. WDYT?
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.
@Godin Let's keep things simple and remove "class" also in the test.
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.
@marchof just to clarify: so accepting that agent will generate message without word "class" ?
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.
@Godin Absolutely! In the context of the agent and the class name it should be obvious that classes get instrumented.
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.
@marchof done. Note that I also did other changes to cover remaining missing cases.
Hey, thanks for this |
3b7a58b
to
fbc10b5
Compare
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.
@Godin I propose a minor change to remove duplicated code.
@@ -154,17 +156,19 @@ protected String getCommonSuperClass(final String type1, | |||
*/ | |||
public void instrument(final InputStream input, final OutputStream output, | |||
final String name) throws IOException { | |||
final byte[] bytes; |
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 think we can delegate to the overloaded method here:
public void instrument(final InputStream input, final OutputStream output,
final String name) throws IOException {
output.write(instrument(input, name));
}
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.
@marchof indeed... and done
@marchof BTW while working on this I noticed that Javadocs states
but what about case when write fails? Also was wondering how consumers such as Ant Task behave in such case... |
@Godin I was thinking the same. But there will be a specific IOException naming the file which cannot be written. Generating the class data itself is already protected within the |
In #400 we updated
Analyzer
, but notInstrumenter
.So that for example for the same
broken.zip
Analyzer.analyzeAll
produces:while
Instrumenter.instrumentAll
:This difference is also visible between Ant tasks
report
andinstrument
when they used for archives that contain corrupted nested archives - in a stack trace in case ofreport
name of a nested corrupted archive is shown, while in case ofinstrument
not.