-
Notifications
You must be signed in to change notification settings - Fork 1k
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
enable error-prone "narrow calculation" check #11923
Conversation
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 changes and it found good overflow bugs!
This NarrowCalculation is specific to multiplication, which was the issue for #11905. It would not have detected the multiplication issue for the bug before that (#11861), as that one never involved Instead here, the idea is that its always suspicious if you see The "IntLongMath" is more aggressive and looks at not just multiplication but other operations too. example of other stuff it picks up:
Hence I'm not sure about enabling |
@uschindler @risdenk if you want to take another pass, it would be helpful. I don't want to introduce new risks here with this change. |
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.
I approve this. See also my comment about the idea to extend Counter class by subtractAndGet
This reverts commit 82ac50d. Welcome to the bikeshed :)
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.
I aprove the original version again. Thanks!
just hash out how you want the style of the bytesrefhash code to be as we are going back and forth here. a little sad as i thought spotless was the end of the java style bikesheds :) ill check back in a few days. |
@rmuir just some question about cases like |
All fine! I vote: merge this ASAP :-) |
A sorry, yes it is a bug for small integers. It is explained in the errorprone bug docs: https://errorprone.info/bugpattern/NarrowCalculation Sorry for asking! |
yes, some of the time the code was doing |
This check finds bugs such as #11905. See https://errorprone.info/bugpattern/NarrowCalculation
This check finds bugs such as #11905. See https://errorprone.info/bugpattern/NarrowCalculation
@@ -85,7 +85,7 @@ final class DocumentsWriterFlushControl implements Accountable, Closeable { | |||
this.perThreadPool = documentsWriter.perThreadPool; | |||
this.flushPolicy = config.getFlushPolicy(); | |||
this.config = config; | |||
this.hardMaxBytesPerDWPT = config.getRAMPerThreadHardLimitMB() * 1024 * 1024; | |||
this.hardMaxBytesPerDWPT = config.getRAMPerThreadHardLimitMB() * 1024L * 1024L; |
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.
i think the thing to do here would have been
Math.multiplyExact(config.getRAMPerThreadHardLimitMB(), 1024 * 1024);
It seems it's invalid if this is every more than can be contained in an integer?:
lucene/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java
Lines 343 to 359 in b5795db
/** | |
* Expert: Sets the maximum memory consumption per thread triggering a forced flush if exceeded. A | |
* {@link DocumentsWriterPerThread} is forcefully flushed once it exceeds this limit even if the | |
* {@link #getRAMBufferSizeMB()} has not been exceeded. This is a safety limit to prevent a {@link | |
* DocumentsWriterPerThread} from address space exhaustion due to its internal 32 bit signed | |
* integer based memory addressing. The given value must be less that 2GB (2048MB) | |
* | |
* @see #DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB | |
*/ | |
public IndexWriterConfig setRAMPerThreadHardLimitMB(int perThreadHardLimitMB) { | |
if (perThreadHardLimitMB <= 0 || perThreadHardLimitMB >= 2048) { | |
throw new IllegalArgumentException( | |
"PerThreadHardLimit must be greater than 0 and less than 2048MB"); | |
} | |
this.perThreadHardLimitMB = perThreadHardLimitMB; | |
return this; | |
} |
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.
sounds good to me! if you want to make a PR with more cleanups/safety/fixes, let's get them in.
This check finds bugs such as #11905.
For that particular bug, the error messages look like this:
See https://errorprone.info/bugpattern/NarrowCalculation for more information.
Closes #11910