Repository navigation
[core] Fix off-by-one error in AbstractJjtreeNode.fitTokensToChildren() - #7061
Conversation
|
Compared to main: (comment created at 2026-09-12 16:18:02+00:00 for 64b2255) |
|
|
||
| @Test | ||
| void testDummy() { | ||
| // Without this, the test will fail?! |
There was a problem hiding this comment.
The exception "No Tests have been executed in Test Set" is coming from https://github.com/pmd/build-tools/blob/8e1706f38c8956527396ffb6e57ce836b9bf1281/src/main/java/net/sourceforge/pmd/buildtools/surefire/junit/TestExecutionListener.java#L81
IIRC, I've added this, because we had cases (maybe with kotest, maybe normal JUnit tests), where we had many test methods, but no tests have ever been executed and the build is green, giving a very false sense of safety...
This is activated by the configuration for surefire plugin:
Lines 350 to 371 in 07cf000
Describe the PR
I've been browsing through sonar, and I think it has found a valid off-by-one bug here. If
index == getNumChildren()istrue,getChild(index)will throw anArrayIndexOutOfBoundsException.This issue never shows, because
insertChildis only ever used to insert at the front, never at the back. Still, I think this problem should be fixed. But this means there is no reproduction test case to verify.This PR closes the bug and adds unit tests for
AbstractJjtreeNode.insertChild. I'm not quite happy with the latter. The mocks forcompareToon the tokens only do enough for the code to run, But they don't follow the contract of Comparable. Improvements are welcome.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)