-
Notifications
You must be signed in to change notification settings - Fork 2.7k
chore: DefaultUpdateCheckManager
Fix variable 'lock' is never used (PMD: UnusedPrivateField)
#2376
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
base: master
Are you sure you want to change the base?
chore: DefaultUpdateCheckManager
Fix variable 'lock' is never used (PMD: UnusedPrivateField)
#2376
Conversation
2fb927a
to
0999cbd
Compare
...maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java
Outdated
Show resolved
Hide resolved
@@ -303,7 +301,7 @@ private Properties read(File touchfile) { | |||
Properties props = new Properties(); | |||
|
|||
try (FileInputStream in = new FileInputStream(touchfile)) { | |||
try (FileLock lock = in.getChannel().lock(0, Long.MAX_VALUE, true)) { | |||
try (FileLock ignored = in.getChannel().lock(0, Long.MAX_VALUE, true)) { |
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.
It's not ignored. Is PMD simply wrong here?
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.
really? check out the usage. It seems unused.
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.
@desruisseaux point out correctly that its used indirectly
, having the implizit close()
call.
As IDEA and PMD both point this out is seems ok to rename to give proper context. Its ignored as handled by default.
Other way should be an inline comment for suppression.
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.
It's used by the try with resources auto-close. See https://stackoverflow.com/questions/70773389/try-with-resource-without-declaring-variable
Unless you can remove the variable, PMD is wrong that this is unused. Maybe Idea is too.
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.
indeed. This is the only use, which is an exception of the normal pattern (using is explizit).
To make this clear the convention seems naming it ignored
, at least considering IDEA and PMD, both recognize the variable as marked explizit, as only used implicit.
Now using the resource which the statement is all about, seems like an error, thats why its pointes out by these tools.
Im altho wondering why its not used, allowing a comment to explain too.
Then the comment end up in the code again, to be self explaining.
impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java
Outdated
Show resolved
Hide resolved
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.
the block is super small, its defacto unused or im not Vincent Potucek.
@@ -303,7 +301,7 @@ private Properties read(File touchfile) { | |||
Properties props = new Properties(); | |||
|
|||
try (FileInputStream in = new FileInputStream(touchfile)) { | |||
try (FileLock lock = in.getChannel().lock(0, Long.MAX_VALUE, true)) { |
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.
its is an error indication, therefore should be named according to convention.
@@ -303,7 +301,7 @@ private Properties read(File touchfile) { | |||
Properties props = new Properties(); | |||
|
|||
try (FileInputStream in = new FileInputStream(touchfile)) { | |||
try (FileLock lock = in.getChannel().lock(0, Long.MAX_VALUE, true)) { | |||
try (FileLock ignored = in.getChannel().lock(0, Long.MAX_VALUE, true)) { |
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.
really? check out the usage. It seems unused.
0999cbd
to
693590a
Compare
It is used implicitly in a implicit |
…MD: UnusedPrivateField)
693590a
to
2483ec9
Compare
yes, then it should be named accordingly. |
dont we have test for this lock? afaik the lock only gets closed but not like open or checked if its ready to go. So calling this should do the trick as well: |
@@ -303,7 +301,7 @@ private Properties read(File touchfile) { | |||
Properties props = new Properties(); | |||
|
|||
try (FileInputStream in = new FileInputStream(touchfile)) { | |||
try (FileLock lock = in.getChannel().lock(0, Long.MAX_VALUE, true)) { | |||
try (FileLock ignored = in.getChannel().lock(0, Long.MAX_VALUE, true)) { |
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.
It's used by the try with resources auto-close. See https://stackoverflow.com/questions/70773389/try-with-resource-without-declaring-variable
Unless you can remove the variable, PMD is wrong that this is unused. Maybe Idea is too.
No description provided.