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

[MSHARED-1248] maven-dependency-analyzer should log instead of failing #89

Merged
merged 3 commits into from
Jun 25, 2023

Conversation

garydgregory
Copy link
Member

[MSHARED-1248] maven-dependency-analyzer should log instead of failing when analyzing a corrupted jar file

https://issues.apache.org/jira/browse/MSHARED-1248

@@ -71,7 +71,7 @@ public void visitClass(String className, InputStream in) {
reader.accept(classVisitor, 0);
} catch (IOException exception) {
exception.printStackTrace();
} catch (IndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException | IllegalArgumentException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment below doesn't apply to the new exception. It's probably better to make this a spearate catch block with a more descriptive error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @elharo
I rewrote the catch clause per your suggestion.

Comment on lines 79 to 80
// [MSHARED-1248] should log instead of failing when analyzing a corrupted jar file
logger.warn("Unable to process: " + className, e);
Copy link
Member

Choose a reason for hiding this comment

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

I'm still not sure if it will be the best solution.
Eg. when analyzer will not support jdk in newer version - user will only have a warnings but nothing will be analyzed.
We know that warnings are many times ignored ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @slawekjaranowski
I'm not sure how else you propose to solve https://issues.apache.org/jira/browse/MSHARED-1248
Ideas?

Copy link
Member

Choose a reason for hiding this comment

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

As I see all project production and tests classes are analyzed.
Maybe allowing exclusion for some path, patterns will be what we need.

In specific project we know which classes are broken and which should be excluded.

So we not need to ignore errors when we will can exclude what we want.

@garydgregory - What do you think?

@garydgregory
Copy link
Member Author

@slawekjaranowski
That sounds reasonable but much more complicated, which I am ok with as long the use case in the jira ticket can be handled. So I guess you can close this ticket but I am not sure who will do this work.

@elharo
Copy link
Contributor

elharo commented Jun 19, 2023

I think this PR is the better approach. Excluding files only works when you know in advance which files are corrupt. I know from experience that's not always true. There are corrupt jar files in the wild, including a few in Maven Central. The general principle in play is that tools should accept any input, including arbitrary byte sequences that do not meet expectations, and gracefully reject them without crashing. In this case that means the dependency analyzer should log the problem with a particular jar file and continue with the rest of the build.

Since the dependency analyzer is a library, not a plugin, it should never abort the build. It can report the issues it detects up the chain to plugins that can be configured to respond to a corrupt jar in the way that makes the most sense for the particular project.

@@ -75,6 +75,9 @@ public void visitClass(String className, InputStream in) {
// some bug inside ASM causes an IOB exception. Log it and move on?
// this happens when the class isn't valid.
logger.warn("Unable to process: " + className);
} catch (IllegalArgumentException e) {
// [MSHARED-1248] should log instead of failing when analyzing a corrupted jar file
logger.warn("Unable to process: " + className, e);
Copy link
Contributor

@elharo elharo Jun 19, 2023

Choose a reason for hiding this comment

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

Make this log message distinct. E.g. "Byte code of " + className + " is corrupt" and possibly include the name or path of the jar file in which the class appears.

Copy link
Member Author

Choose a reason for hiding this comment

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

@elharo
I updated the message. I do not see where to get a path since we are starting from an InputStream.

@@ -75,6 +75,9 @@ public void visitClass(String className, InputStream in) {
// some bug inside ASM causes an IOB exception. Log it and move on?
// this happens when the class isn't valid.
logger.warn("Unable to process: " + className);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be helpful to include the exception in the warning here as well

Copy link
Member Author

@garydgregory garydgregory Jun 19, 2023

Choose a reason for hiding this comment

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

@elharo
I updated the call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants