Skip to content

NullPointerException in TextBlockGoogleStyleFormatting with text blocks in annotations #18381

Closed

Description

@eorloff

I have read check documentation: https://checkstyle.org/checks/coding/textblockgooglestyleformatting.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

$ javac Example.java

$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
  "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
  "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="TextBlockGoogleStyleFormatting"/>
  </module>
</module>
$ cat Example.java
@SuppressWarnings(
  """
  Text block in annotation.
  """)
public class Example {
}
$ RUN_LOCALE="-Duser.language=en -Duser.country=US"

$ java $RUN_LOCALE -jar checkstyle-12.3.0-all.jar -c config.xml Example.java
Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing Example.java
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:313)
        at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:227)
        at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:429)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:347)
        at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:206)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:130)
Caused by: java.lang.NullPointerException: Cannot invoke "com.puppycrawl.tools.checkstyle.api.DetailAST.getType()" because "parent" is null
        at com.puppycrawl.tools.checkstyle.checks.coding.TextBlockGoogleStyleFormattingCheck.openingQuotesAreAloneOnTheLine(TextBlockGoogleStyleFormattingCheck.java:136)
        at com.puppycrawl.tools.checkstyle.checks.coding.TextBlockGoogleStyleFormattingCheck.visitToken(TextBlockGoogleStyleFormattingCheck.java:87)
        at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:390)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:463)
        at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:328)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:208)
        at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:101)
        at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:341)
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:300)
        ... 5 more
Checkstyle ends with 1 errors.

I expect checkstyle to not throw report any issues in the code and not fail with a NullPointerException.

The above example is a minimal example using @SuppressWarnings since that is an annotation that is available without libraries. The problem was encountered using another annotation where using a text block was more meaningful.


Activity

  1. romani commented on Dec 19, 2025

    @romani
    Member

    @mohitsatr , we need hot fix.

    @eorloff , do you have any opensource project that uses """ in such or more advanced way ? to let run validiton on it to make sure there is no other interesting cases of """ usage.

  2. eorloff commented on Dec 19, 2025

    @eorloff
    ContributorAuthor

    @romani Unfortunately I do not have any opensource project where it is used. I encountered the problem when using jakarta.persistence.NamedNativeQuery and wanting to specify the query using a text block.

    Searching Github I found this example that does something similar:
    https://github.com/RedHatInsights/rhsm-subscriptions/blob/03fdeb5f7e60ec31217572e702207cd9712c5a59/src/main/java/org/candlepin/subscriptions/inventory/db/model/InventoryHost.java#L96

  3. romani commented on Dec 19, 2025

    @romani
    Member
  4. eorloff commented on Dec 19, 2025

    @eorloff
    ContributorAuthor

    @romani I have just encountered the issue in another context that is available as opensource. Here the problem is encountered when configured picocli: https://gitlab.com/partisiablockchain/language/partisia-cli/-/blob/main/src/main/java/com/partisiablockchain/language/partisiacli/account/create/Create.java#L39

    I hope that can help iron out the problem.

  5. DakshRJain737 commented on Dec 19, 2025

    @DakshRJain737
    Contributor

    @romani came across the same problem while solving Issue: #18309 under the PR: #18309

  6. added a commit that references this issue on Dec 20, 2025
  7. added a commit that references this issue on Dec 26, 2025
  8. added this to the 12.3.1 milestone on Dec 26, 2025
  9. romani commented on Dec 26, 2025

    @romani
    Member

    fix is merged.

    @eorloff , I hope this exception is not blocking you, and I can release it on last weekend of month, Dec 31. But I can do it quicker if you need.

  10. added a commit that references this issue on Jan 4, 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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions