Repository navigation
Closed
Description
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
romani commentedon Dec 19, 2025
@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.eorloff commentedon Dec 19, 2025
@romani Unfortunately I do not have any opensource project where it is used. I encountered the problem when using
jakarta.persistence.NamedNativeQueryand 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
romani commentedon Dec 19, 2025
thanks a lot
they actually use some fork of google style https://github.com/RedHatInsights/rhsm-subscriptions/blob/03fdeb5f7e60ec31217572e702207cd9712c5a59/config/checkstyle/checkstyle.xml ,so it good testing project.
eorloff commentedon Dec 19, 2025
@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.
DakshRJain737 commentedon Dec 19, 2025
@romani came across the same problem while solving Issue: #18309 under the PR: #18309
Issue checkstyle#18381: Fix NPE in TextBlockGoogleStyleFormatting Tex…
Praveen7294 commentedon Dec 21, 2025
@romani Please use Apache Pulsar, as it has multiple usages of Java text blocks.
some of them are:
https://github.com/apache/pulsar/blob/621b41f506764bc9573d2b2496620612cfb1ae36/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImplTest.java#L1943
https://github.com/apache/pulsar/blob/621b41f506764bc9573d2b2496620612cfb1ae36/pulsar-broker-auth-oidc/src/test/java/org/apache/pulsar/broker/authentication/oidc/AuthenticationProviderOpenIDIntegrationTest.java#L112
https://github.com/apache/pulsar/blob/621b41f506764bc9573d2b2496620612cfb1ae36/pulsar-broker/src/test/java/org/apache/pulsar/schema/compatibility/SchemaCompatibilityCheckTest.java#L546
Issue #18381: Fix NPE in TextBlockGoogleStyleFormatting Textblocks wi…
romani commentedon Dec 26, 2025
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.
Issue checkstyle#18381: Fix NPE in TextBlockGoogleStyleFormatting Tex…