You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/11/15 12:18:03 UTC

[GitHub] [lucene] rmuir opened a new issue, #11932: enable error-prone NarrowingCompoundAssignment check

rmuir opened a new issue, #11932:
URL: https://github.com/apache/lucene/issues/11932

   ### Description
   
   A great overflow issue: https://errorprone.info/bugpattern/NarrowingCompoundAssignment
   
   javac is getting its own checker for this in version 20 so eventually we can switch to that one. But for now, i'd like to try to enable the error-prone version.
   
   in a nutshell, compound assignment operators are totally lenient:
   ```
   jshell> byte x = 0;
   x ==> 0
   
   jshell> x = x + Long.MAX_VALUE;
   |  Error:
   |  incompatible types: possible lossy conversion from long to byte
   |  x = x + Long.MAX_VALUE;
   |      ^----------------^
   
   jshell> x += Long.MAX_VALUE;
   $2 ==> -1
   ```


-- 
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: issues-unsubscribe@lucene.apache.org.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] rmuir closed issue #11932: one-time pass thru error-prone NarrowingCompoundAssignment check

Posted by GitBox <gi...@apache.org>.
rmuir closed issue #11932: one-time pass thru error-prone NarrowingCompoundAssignment check
URL: https://github.com/apache/lucene/issues/11932


-- 
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: issues-unsubscribe@lucene.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] rmuir commented on issue #11932: enable error-prone NarrowingCompoundAssignment check

Posted by GitBox <gi...@apache.org>.
rmuir commented on issue #11932:
URL: https://github.com/apache/lucene/issues/11932#issuecomment-1315236305

   There's a fair amount of noise to the check (a lot of code uses these operators to do crazy bit twiddling stuff etc), but it finds some good stuff that we should obviously fix. including at least another overflow in vectors :)
   
   


-- 
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: issues-unsubscribe@lucene.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] rmuir commented on issue #11932: enable error-prone NarrowingCompoundAssignment check

Posted by GitBox <gi...@apache.org>.
rmuir commented on issue #11932:
URL: https://github.com/apache/lucene/issues/11932#issuecomment-1315559541

   Here's a log of the output from the new check: [overflow.log](https://github.com/apache/lucene/files/10014404/overflow.log)
   
   I think it is too noisy to worry about fixing all the code. I plan to do a single pass through it and fix anything that looks "real". For example places where, `int` accumulator is accidentally used to sum up `long` values with `+=`. In these cases the wrong type was used but java threw away all safety thanks to `+=`.
   
   Example: 
   ```
   /home/rmuir/workspace/lucene/lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsWriter.java:141: warning: [NarrowingCompoundAssignment] Compound assignments from long to int hide lossy casts
           totalCost += sub.values.cost();
                     ^
       (see https://errorprone.info/bugpattern/NarrowingCompoundAssignment)
     Did you mean 'totalCost = (int) (totalCost + sub.values.cost());'?
   ```
   In this case KnnVectorsWriter `totalCost` should simply be a `long` instead of `int`. 
   
   Another similar one:
   ```
   /home/rmuir/workspace/lucene/lucene/core/src/java/org/apache/lucene/util/OfflineSorter.java:302: warning: [NarrowingCompoundAssignment] Compound assignments from long to int hide lossy casts
           sortInfo.lineCount += part.count;
   ```
   In this case we should change `sortInfo.lineCount` to be a `long` instead of `int`.


-- 
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: issues-unsubscribe@lucene.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] jpountz commented on issue #11932: one-time pass thru error-prone NarrowingCompoundAssignment check

Posted by GitBox <gi...@apache.org>.
jpountz commented on issue #11932:
URL: https://github.com/apache/lucene/issues/11932#issuecomment-1315648711

   I'll look into this log.


-- 
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: issues-unsubscribe@lucene.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org