You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "dant3 (via GitHub)" <gi...@apache.org> on 2024/03/07 09:22:38 UTC

[PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

dant3 opened a new pull request, #3373:
URL: https://github.com/apache/ignite-3/pull/3373

   This PR inroduces additional static analysis tool: SpotBugs.
   Some of the problems found was fixed as part of this patch, or suppressed as being false-positives.
   
   List of tickets for issues worth checking raised as a result of this work:
   
   * [IGNITE-21690](https://issues.apache.org/jira/browse/IGNITE-21690) ConfigurationNode has inconsistent synchronized access to fields `invalid` and `val`
   * [IGNITE-21691](https://issues.apache.org/jira/browse/IGNITE-21691) BasicMetricExporter has inconsistent synchronized access to field `configuration`
   * [IGNITE-21693](https://issues.apache.org/jira/browse/IGNITE-21693) TxManagerImpl increments/decrements volatile field `inflights`
   * [IGNITE-21694](https://issues.apache.org/jira/browse/IGNITE-21694) HeapLockManager/HeapUnboundedLockManager makes inefficient use of keySet iterator instead of entrySet iterator
   * [IGNITE-21700](https://issues.apache.org/jira/browse/IGNITE-21700) IgniteSort: result of RelOptCost.plus is ignored but it doesn’t have side-effects
   * [IGNITE-21701](https://issues.apache.org/jira/browse/IGNITE-21701) IgniteSender compares unrelated types
   * [IGNITE-21695](https://issues.apache.org/jira/browse/IGNITE-21695) PageHandler: useless control flow
   * [IGNITE-21699](https://issues.apache.org/jira/browse/IGNITE-21699) DistributionFunction compares strings by reference
   * [IGNITE-21702](https://issues.apache.org/jira/browse/IGNITE-21702) AbstractNode field `inBufSize` is unused
   * [IGNITE-21703](https://issues.apache.org/jira/browse/IGNITE-21703) IgniteSqlFunctions.octetLength relies on default encoding
   * [IGNITE-21704](https://issues.apache.org/jira/browse/IGNITE-21704) ConfigurationListenerHolder uses weird equals implementation
   * [IGNITE-21705](https://issues.apache.org/jira/browse/IGNITE-21705) CheckpointWorkflow uses weird equals implementation
   * [IGNITE-21706](https://issues.apache.org/jira/browse/IGNITE-21706) RandomLruPageReplacementPolicy has dead conditions
   * [IGNITE-21692](https://issues.apache.org/jira/browse/IGNITE-21692) AbstractFreeList has unused private method `initReusedPage`
   * [IGNITE-21696](https://issues.apache.org/jira/browse/IGNITE-21696) LazyStripedExecutor performs synchronization on AtomicReferenceArray
   * [IGNITE-21697](https://issues.apache.org/jira/browse/IGNITE-21697) ConnectionManager ignores exceptional return value of ExecutorService.submit
   * [IGNITE-21698](https://issues.apache.org/jira/browse/IGNITE-21698) LocalConfigurationStorage reboxes unboxed value
   
   
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1515866836


##########
gradle/libs.versions.toml:
##########
@@ -256,3 +259,5 @@ awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility"
 progressBar = { module = "me.tongfei:progressbar", version.ref = "progressBar" }
 
 jna = { module = "net.java.dev.jna:jna", version.ref = "jna"}
+
+spotbugs-plugins-secbugs = "com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0"

Review Comment:
   that line is actually redundant, i'll remove it :)



##########
gradle/libs.versions.toml:
##########
@@ -256,3 +259,5 @@ awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility"
 progressBar = { module = "me.tongfei:progressbar", version.ref = "progressBar" }
 
 jna = { module = "net.java.dev.jna:jna", version.ref = "jna"}
+
+spotbugs-plugins-secbugs = "com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0"

Review Comment:
   that piece is actually redundant, i'll remove it :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1515866332


##########
buildscripts/java-integration-test.gradle:
##########
@@ -89,3 +89,7 @@ tasks.register('jacocoIntegrationTestReport', JacocoReport) {
         html.required = true
     }
 }
+
+spotbugsIntegrationTest {
+    enabled(false)
+}

Review Comment:
   Yeah. Also it's worth to add it to the project editor configuration so that editor does that by default.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1519932090


##########
modules/core/src/main/java/org/apache/ignite/internal/util/ExceptionUtils.java:
##########
@@ -951,7 +951,7 @@ <T extends Throwable> T copy(MethodHandle constructor, UUID traceId, int code, S
      * </code></pre>
      *
      */
-    private static class UtilException extends Throwable {
+    private static class UtilException extends RuntimeException {

Review Comment:
   Sure. The reason is basically correctness.  Currently this exception is never caught but it seems it's designed exactly to be caught.
   It's usually bad idea to catch Throwable because it's hierarchy contains Error class, which includes OutOfMemoryError for instance. On the other hand catching Exceptions, be it RuntineException or not is fine. 
   If that class is a RuntimeException it will be caught by catch(Exception) blocks but will remain unchecked since it's a runtime exception, which is what was the intended behaviour here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1516030935


##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/Checkpointer.java:
##########
@@ -634,10 +634,9 @@ public void cancel() {
             log.debug("Cancelling grid runnable: " + this);
         }
 
-        // Do not interrupt runner thread.
-        isCancelled.set(true);
-
         synchronized (this) {
+            // Do not interrupt runner thread.
+            isCancelled.set(true);

Review Comment:
   Ok. I'll add it to exclusions then



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1516052528


##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/Checkpointer.java:
##########
@@ -634,10 +634,9 @@ public void cancel() {
             log.debug("Cancelling grid runnable: " + this);
         }
 
-        // Do not interrupt runner thread.
-        isCancelled.set(true);
-
         synchronized (this) {
+            // Do not interrupt runner thread.
+            isCancelled.set(true);

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1519932090


##########
modules/core/src/main/java/org/apache/ignite/internal/util/ExceptionUtils.java:
##########
@@ -951,7 +951,7 @@ <T extends Throwable> T copy(MethodHandle constructor, UUID traceId, int code, S
      * </code></pre>
      *
      */
-    private static class UtilException extends Throwable {
+    private static class UtilException extends RuntimeException {

Review Comment:
   Sure. The reason is basically correctness.  Currently this exception is not the one you would usually catch but it seems it's designed exactly to be caught.
   It's usually bad idea to catch Throwable because it's hierarchy contains Error class, which includes OutOfMemoryError for instance. On the other hand catching Exceptions, be it RuntineException or not is fine. 
   If that class is a RuntimeException it will be caught by catch(Exception) blocks but will remain unchecked since it's a runtime exception, which is what was the intended behaviour here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "sk0x50 (via GitHub)" <gi...@apache.org>.
sk0x50 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1521556200


##########
modules/core/src/main/java/org/apache/ignite/internal/util/ExceptionUtils.java:
##########
@@ -951,7 +951,7 @@ <T extends Throwable> T copy(MethodHandle constructor, UUID traceId, int code, S
      * </code></pre>
      *
      */
-    private static class UtilException extends Throwable {
+    private static class UtilException extends RuntimeException {

Review Comment:
   >  Currently this exception is not the one you would usually catch but it seems it's designed exactly to be caught.
   This exception was introduced due to internal technical needs. It is not assumed that it can be thrown directly.
   However, in this particular case, the exact type does not matter, we can use `RuntimeException`. 



##########
modules/core/src/main/java/org/apache/ignite/internal/util/ExceptionUtils.java:
##########
@@ -951,7 +951,7 @@ <T extends Throwable> T copy(MethodHandle constructor, UUID traceId, int code, S
      * </code></pre>
      *
      */
-    private static class UtilException extends Throwable {
+    private static class UtilException extends RuntimeException {

Review Comment:
   >  Currently this exception is not the one you would usually catch but it seems it's designed exactly to be caught.
   
   This exception was introduced due to internal technical needs. It is not assumed that it can be thrown directly.
   However, in this particular case, the exact type does not matter, we can use `RuntimeException`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "alievmirza (via GitHub)" <gi...@apache.org>.
alievmirza commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1515876279


##########
modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java:
##########
@@ -346,7 +347,7 @@ private void signalNextWaiter(int writeWaitCnt, int idx) {
      *      the write lock without leaving a gap. Returns {@code false} otherwise, in this case the resource
      *      state must be re-validated.
      */
-    public Boolean upgradeToWriteLock(long lock, int tag) {
+    public @Nullable Boolean upgradeToWriteLock(long lock, int tag) {

Review Comment:
   Hm, I've looked a bit closer and it's true that this method can return `null` as a valid outcome, so my comment is incorrect.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander merged PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1515859704


##########
modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java:
##########
@@ -346,7 +347,7 @@ private void signalNextWaiter(int writeWaitCnt, int idx) {
      *      the write lock without leaving a gap. Returns {@code false} otherwise, in this case the resource
      *      state must be re-validated.
      */
-    public Boolean upgradeToWriteLock(long lock, int tag) {
+    public @Nullable Boolean upgradeToWriteLock(long lock, int tag) {

Review Comment:
   Javadoc and the code of the method states that it can return null, so I didn't changed that since i'm not the code owner. Maybe it's worth to raise separate issue for that?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1515854554


##########
gradle/libs.versions.toml:
##########
@@ -256,3 +259,5 @@ awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility"
 progressBar = { module = "me.tongfei:progressbar", version.ref = "progressBar" }
 
 jna = { module = "net.java.dev.jna:jna", version.ref = "jna"}
+
+spotbugs-plugins-secbugs = "com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0"

Review Comment:
   Trailing newline



##########
buildscripts/java-integration-test.gradle:
##########
@@ -89,3 +89,7 @@ tasks.register('jacocoIntegrationTestReport', JacocoReport) {
         html.required = true
     }
 }
+
+spotbugsIntegrationTest {
+    enabled(false)
+}

Review Comment:
   A trailing newline is missing. We should probably have this automatically checked.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "sk0x50 (via GitHub)" <gi...@apache.org>.
sk0x50 commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1519740966


##########
modules/core/src/main/java/org/apache/ignite/internal/util/ExceptionUtils.java:
##########
@@ -951,7 +951,7 @@ <T extends Throwable> T copy(MethodHandle constructor, UUID traceId, int code, S
      * </code></pre>
      *
      */
-    private static class UtilException extends Throwable {
+    private static class UtilException extends RuntimeException {

Review Comment:
   Could you please clarify this change? What is the reason for this? Just in case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "tkalkirill (via GitHub)" <gi...@apache.org>.
tkalkirill commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1515927928


##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/Checkpointer.java:
##########
@@ -634,10 +634,9 @@ public void cancel() {
             log.debug("Cancelling grid runnable: " + this);
         }
 
-        // Do not interrupt runner thread.
-        isCancelled.set(true);
-
         synchronized (this) {
+            // Do not interrupt runner thread.
+            isCancelled.set(true);

Review Comment:
   You need to return it back, taking the monitor may take longer than it seems at first glance, and `isCancelled` is also read without a monitor.



##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/PersistentPageMemory.java:
##########
@@ -519,9 +519,9 @@ public long allocatePage(int grpId, int partId, byte flags) throws IgniteInterna
 
         seg.writeLock().lock();
 
-        FullPageId fullId = new FullPageId(pageId, grpId);
 
         try {
+            FullPageId fullId = new FullPageId(pageId, grpId);

Review Comment:
   ```suggestion
               FullPageId fullId = new FullPageId(pageId, grpId);
               
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "alievmirza (via GitHub)" <gi...@apache.org>.
alievmirza commented on code in PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#discussion_r1515848185


##########
modules/core/src/main/java/org/apache/ignite/internal/util/OffheapReadWriteLock.java:
##########
@@ -346,7 +347,7 @@ private void signalNextWaiter(int writeWaitCnt, int idx) {
      *      the write lock without leaving a gap. Returns {@code false} otherwise, in this case the resource
      *      state must be re-validated.
      */
-    public Boolean upgradeToWriteLock(long lock, int tag) {
+    public @Nullable Boolean upgradeToWriteLock(long lock, int tag) {

Review Comment:
   Seems like `Boolean` could be changed to `boolean`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-21569 introduced spotbugs checks for additional code static analysis [ignite-3]

Posted by "dant3 (via GitHub)" <gi...@apache.org>.
dant3 commented on PR #3373:
URL: https://github.com/apache/ignite-3/pull/3373#issuecomment-1983380661

   Suggestions i got so far has been addressed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org