-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix unused stream in DefaultPluginXmlFactory#write
#2303
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
Conversation
| } else if (outputStream != null) { | ||
| new PluginDescriptorStaxWriter().write(outputStream, content); | ||
| } else { | ||
| try (OutputStream os = Files.newOutputStream(path)) { |
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.
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 looks like a critical bug and easy to prevent: https://checkstyle.sourceforge.io/checks/coding/unusedlocalvariable.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.
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.
You wanna try adding the rule check to the PR ?
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.
its a bug in checkstyle we already have this checker in place:
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.
What version of checkstyle is in use?
Please share link to config also
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.
Please share link to config also
config is mystery ATM as it comes from cloud.
Will update, thanks.
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.
Congo is inherited from parent, but there is a way to override it and complement with the rules needed. You need to analyze how check style is configured in the parent.
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.
We have this bug reproducible and tested already in
So its nice to have this info, but not mandatory anymore.
|
[INFO] BUILD SUCCESS |
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java
Outdated
Show resolved
Hide resolved
fix DefaultPluginXmlFactory#writefix unused stream in DefaultPluginXmlFactory#write
gnodet
left a comment
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.
Nice catch !
fix unused stream in DefaultPluginXmlFactory#write|
ty, will add tc as well. |
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java
Show resolved
Hide resolved
| } | ||
|
|
||
| /** | ||
| * Simply converts the given content to an XML string. |
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.
| } | ||
|
|
||
| /** | ||
| * Simply parse the given xml string. |
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.
less is more - kiss.
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java
Show resolved
Hide resolved
| nonNull(request, "request"); | ||
| Path path = request.getPath(); | ||
| URL url = request.getURL(); | ||
| Reader reader = request.getReader(); |
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.
With this SOC, we get better visibility into the system and can avoid unnecessary complexity in the code. The current implementation is already clean and follows a functional OOP style, but it's not the final version. There's still room to extract dedicated abstraction layers to support more specialized responsibilities.
However, this approach currently mimics fields of a class, which introduces coupling and reduces cohesion. It leans into feature envy and bypasses SOLID design principles and established architectural patterns. We should aim to refactor accordingly.
stream in DefaultPluginXmlFactory#write
gnodet
left a comment
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.
Removed too much.
Please don't refactor too much without care.
yes
test first this changes already and things get simpler |
Not sure what you mean, but you removed support for URLs for no good reason. Your first commit what correct, now the PRs is not acceptable. |
stream in DefaultPluginXmlFactory#writeDefaultPluginXmlFactory#write
DefaultPluginXmlFactory#writeDefaultPluginXmlFactory#write
DefaultPluginXmlFactory#writeDefaultPluginXmlFactory#write
DefaultPluginXmlFactory#writeDefaultPluginXmlFactory#write
DefaultPluginXmlFactory#writestream in DefaultPluginXmlFactory#write
stream in DefaultPluginXmlFactory#writestream os in DefaultPluginXmlFactory#write
yes im sorry. lets SOC this merge and check on follow up to ship this fix and then improve test and everything else dedicated. Thanks for cooperation. Im learn a lot here. |
86735dd to
83cfb4b
Compare
stream os in DefaultPluginXmlFactory#writestream in DefaultPluginXmlFactory#write
| @@ -0,0 +1,255 @@ | |||
| /* | |||
| * Licensed to the Apache Software Foundation (ASF) under one | |||
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.
sorry for high pace. Now bug and test with minimal fix ready to merge and follow up to dig deeper. |
|
You should not raise multiple PRs for the same thing, it becomes a mess and we have no idea what to review. Keep a single PR for one fix and update it. |
|
Yes, wanted to provide quick fix upfront. When merging this the other PR testing everything, therefore having bigger scope could be supplemented. |










Pull #2303: Fix unused
streaminDefaultPluginXmlFactory#writeredundantcode inDefaultPluginXmlFactory:write#2306DefaultModelProcessor#read#2304DefaultModelProcessor#read#2292Blindspot in checkstyle:
osis never used checkstyle/checkstyle#17036tc:
