PHJ2000 opened a new pull request, #779: URL: https://github.com/apache/commons-text/pull/779
Comparing identical vectors containing three `Integer.MAX_VALUE` components returns `-0.33333333457509673` instead of `1.0`. Each individual product fits in a `long`, but their sum overflows the `long` accumulator in `CosineSimilarity.dot()`. Accumulate the dot product in `double`, as the squared norms already do. Keep the `long` multiplication so each integer product is computed without integer overflow before accumulation. Add a parameterized regression test for identical vectors with components `1`, `Integer.MAX_VALUE`, and `Integer.MIN_VALUE`. Validation: - On unmodified production code, `mvn -Dtest=CosineSimilarityTest test` ran 7 tests and failed the two large-value cases. - The published 1.15.0 JAR also reproduces the positive-vector failure. - After the change, the default `mvn` goal passes, including the full test suite, Apache RAT, japicmp, Checkstyle, PMD, SpotBugs, and Javadoc generation (OpenJDK 21.0.12.1, Maven 3.9.11). Jira: pending an Apache Jira account. This PR remains a draft until the report can be filed and its issue key linked here and in the commit message. Checklist from the repository template: - [x] Read the [contribution guidelines](https://github.com/apache/commons-text/blob/master/CONTRIBUTING.md). - [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html). - [x] Used AI: OpenAI Codex investigated the bug, generated the implementation change and regression test, ran validation, and drafted the issue/PR text. No human code-review claim is made. - [x] Run a successful build using the default Maven goal (`mvn`). - [x] Added regression tests that fail without the production change. - [x] Explained what changes, how, and why. - [x] Used a meaningful commit subject and body. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
