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] BaseAntlrTerminalNode should return type instead of index for getTokenKind() · Issue #6471 · pmd/pmd

[core] BaseAntlrTerminalNode should return type instead of index for getTokenKind() #6471

New issue
Copy link
New issue
Copy link
Closed
#6472
Closed
[core] BaseAntlrTerminalNode should return type instead of index for getTokenKind()#6471
#6472
Copy link
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
7.22.0

Description

@stokpop
stokpop
opened on Feb 26, 2026
Issue body actions

Affects PMD Version: 7.21.0

Description:

Creating a custom Kotlin rule using Java we found that BaseAntlrInnerNode#getToken(s) would always return null.

This filter fails:

.filter(it -> it.getTokenKind() == kind)

due to BaseAntlrInnerNode

    protected int getTokenKind() {
        return antlrNode.symbol.getTokenIndex();
    }

Fix is to change that to getType() assuming that type is also kind.

This can fail in antlr4 base Kotlin parser and perhaps also in the Swift parser.

Code Sample demonstrating the issue:

        String code = "class Foo { fun foo() { var a = 42; a += 1 } }";

        // Parse using KotlinParsingHelper
        KtKotlinFile root = KotlinParsingHelper.DEFAULT.parse(code);

        assertNotNull(root);

        // Traverse to the first function declaration in the file
        KtFunctionDeclaration fn = root.descendants(KtFunctionDeclaration.class).first();
        assertNotNull(fn, "Expected a function declaration in the parsed Kotlin file");

        // Find the first KtAssignmentAndOperator node within the function body
        KtAssignmentAndOperator idNode = fn.descendants(KtAssignmentAndOperator.class).first();
        assertNotNull(idNode, "Expected a assignmentAndOperator within the function node");
        // Call the generated accessor that returns the ADD_ASSIGNMENT terminal node.
        // This calls getToken/getTokens under the hood and will exercise
        // BaseAntlrInnerNode#getToken(s).
        TerminalNode tn = idNode.ADD_ASSIGNMENT();
        assertNotNull(tn, "Expected an ADD_ASSIGNMENT terminal node");
        assertEquals("+=", tn.getText());
        assertEquals(ADD_ASSIGNMENT, tn.getSymbol().getType());

Steps to reproduce:

Run the unit test above, will submit this in a PR.

Running PMD through: [custom Kotlin Java rule]

Activity

  1. stokpop
    added
    a:bugPMD crashes or fails to analyse a file.
    on Feb 26, 2026
  2. adangel
    added this to the 7.22.0 milestone on Feb 27, 2026
  3. adangel
    added a commit that references this issue on Feb 27, 2026

    [doc] Update release notes (#6471, #6472)

    41e6b68
  4. adangel
    closed this as completedin #6472on Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.22.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.