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

Provide more context information when unable to read input during instrumentation #527

Merged
merged 1 commit into from May 4, 2017

Conversation

Godin
Copy link
Member

@Godin Godin commented May 3, 2017

In #400 we updated Analyzer, but not Instrumenter.

So that for example for the same broken.zip Analyzer.analyzeAll produces:

java.io.IOException: Error while analyzing /tmp/jacoco/in/broken.zip@brokenentry.txt.

while Instrumenter.instrumentAll:

java.util.zip.ZipException: invalid distance too far back

This difference is also visible between Ant tasks report and instrument when they used for archives that contain corrupted nested archives - in a stack trace in case of report name of a nested corrupted archive is shown, while in case of instrument not.

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

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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" ?

Copy link
Member

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.

Copy link
Member Author

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.

@mathjeff
Copy link

mathjeff commented May 3, 2017

Hey, thanks for this

@Godin Godin force-pushed the issue-527 branch 3 times, most recently from 3b7a58b to fbc10b5 Compare May 4, 2017 14:09
@Godin Godin requested a review from marchof May 4, 2017 14:15
@Godin Godin added this to the 0.7.10 milestone May 4, 2017
Copy link
Member

@marchof marchof left a 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;
Copy link
Member

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));
}

Copy link
Member Author

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 marchof merged commit a973267 into master May 4, 2017
@marchof marchof deleted the issue-527 branch May 4, 2017 18:01
@Godin
Copy link
Member Author

Godin commented May 4, 2017

@marchof BTW while working on this I noticed that Javadocs states

IOException - if reading data from the stream fails or the class can't be instrumented

but what about case when write fails? Also was wondering how consumers such as Ant Task behave in such case...

@marchof
Copy link
Member

marchof commented May 4, 2017

@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 instrument() method.

@jacoco jacoco locked as resolved and limited conversation to collaborators Jan 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants