GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Fix off-by-one error in AbstractJjtreeNode.fitTokensToChildren() by UncleOwen · Pull Request #7061 · pmd/pmd

Conversation

@UncleOwen

@UncleOwen UncleOwen commented Sep 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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() is true, getChild(index) will throw an ArrayIndexOutOfBoundsException.

This issue never shows, because insertChild is 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 for compareTo on the tokens only do enough for the code to run, But they don't follow the contract of Comparable. Improvements are welcome.

Related issues

  • None

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • [n/a] Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
UncleOwen added 3 commits September 11, 2026 18:09
@UncleOwen
Fix off-by-one error in AbstractJjtreeNode.fitTokensToChildren()
9a30135
@UncleOwen
add missing license header
511be3a
@UncleOwen
fix tests
07c3333
@pmd-actions-helper

pmd-actions-helper Bot commented Sep 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-09-12 16:18:02+00:00 for 64b2255)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@UncleOwen
Remove blame.
64b2255
zbynek
zbynek approved these changes Sep 15, 2026
View reviewed changes
@UncleOwen
UncleOwen merged commit 8c73fec into pmd:main Sep 15, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@UncleOwen
UncleOwen deleted the AbstractJjtreeNode-off-by-one branch September 15, 2026 07:06
@UncleOwen UncleOwen added this to the 7.28.0 milestone Sep 15, 2026
adangel
adangel reviewed Sep 15, 2026
View reviewed changes
Comment thread pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/javacc/AbstractJjtreeNodeTest.java

@Test
void testDummy() {
// Without this, the test will fail?!

@adangel adangel Sep 15, 2026

Copy link
Copy Markdown
Member

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.

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:

pmd/pom.xml

Lines 350 to 371 in 07cf000

<statelessTestsetInfoReporter implementation="net.sourceforge.pmd.buildtools.surefire.PMDStatelessTestSetInfoConsoleReporter">
<showFailedTests>true</showFailedTests>
<showSuccessfulTests>false</showSuccessfulTests>
<showSkippedTests>true</showSkippedTests>
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
<usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
</statelessTestsetInfoReporter>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<usePhrasedFileName>true</usePhrasedFileName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-build-tools-config</artifactId>
<version>${pmd.build-tools.version}</version>
</dependency>

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel left review comments
@zbynek zbynek zbynek approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

7.28.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@UncleOwen @zbynek @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.