-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix redundant
code in DefaultPluginXmlFactory:write
#2306
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
DefaultPluginXmlFactory#write
unreachable/dead
code in DefaultPluginXmlFactoryL:103
unreachable/dead
code in DefaultPluginXmlFactoryL:103
unreachable/dead
code in DefaultPluginXmlFactory:103
So no, this is not a dead branch - it serves an important purpose in the API's flexibility. Conclusion: Would you like help adding a unit test to validate this branch? |
But it's redundant then, as the behavior is now the same, and the end result is just without being overly complex and duplicating it—making the default exception explicit. When the default behavior is the same in any case, it’s kind of simpler and should turn out equal in the end, right? So, classic redundancy—time for TDD (aka refactoring). |
unreachable/dead
code in DefaultPluginXmlFactory:103
redundant
code in DefaultPluginXmlFactory:write
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java
Show resolved
Hide resolved
} | ||
} | ||
try (InputStream is = Files.newInputStream(Objects.requireNonNull(path))) { | ||
return xml.read(is, request.isStrict()); | ||
} | ||
} catch (Exception 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.
we shouldn't be catching raw exceptions here; probably fix that first
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.
IOException | XMLStreamException e
need this:
https://checkstyle.sourceforge.io/checks/coding/illegalcatch.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.
Of course, it's better API design to be precise and not broad—especially in this case.
If possible we should ensure this standard as well. In checkstyle
its the same (of course as all the checkers are on), so i know this quite well. Its a good thing to strengthen the design.
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultPluginXmlFactoryTest.java
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultPluginXmlFactoryTest.java
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
void readFromPathParsesPluginDescriptorCorrectly(@TempDir Path tempDir) throws Exception { |
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.
similar
Fix
redundant
code inDefaultPluginXmlFactory:write
- avoidingDRY
increasingcohesion
loweringcoupling
stream
inDefaultPluginXmlFactory#write
#2303fix
unreachable
code:maven/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java
Line 103 in 6be7a12
imho, this branch can never happen:
because of early exit check before
This is too defensive over here. The last
if-else
is the actual final possible condition and therefore should just return:Its
double-trouble
anyway and thereforeDRY violation
- its a smell in eyes. 🎃