Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter throws NullPointerException when javadoc contains '@formatter:off' #410

Closed
ebernard opened this issue Apr 29, 2024 · 1 comment
Milestone

Comments

@ebernard
Copy link

Hi,

I'm trying to reformat my codebase, and everything seems to be working great, except for one class, for which I get a NullPointerException:

[...]
Caused by: java.lang.NullPointerException
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.TokenManager.size (TokenManager.java:84)
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.TokenManager.findIndex (TokenManager.java:150)
    at io.spring.javaformat.formatter.jdk11.eclipse.JavadocLineBreakPreparator$Vistor.visit (JavadocLineBreakPreparator.java:112)
    at io.spring.javaformat.eclipse.jdt.jdk11.core.dom.TagElement.accept0 (TagElement.java:371)
    at io.spring.javaformat.eclipse.jdt.jdk11.core.dom.ASTNode.accept (ASTNode.java:3214)
    at io.spring.javaformat.eclipse.jdt.jdk11.core.dom.ASTNode.acceptChildren (ASTNode.java:3285)
    at io.spring.javaformat.eclipse.jdt.jdk11.core.dom.Javadoc.accept0 (Javadoc.java:194)
    at io.spring.javaformat.eclipse.jdt.jdk11.core.dom.ASTNode.accept (ASTNode.java:3214)
    at io.spring.javaformat.formatter.jdk11.eclipse.JavadocLineBreakPreparator.apply (JavadocLineBreakPreparator.java:62)
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.ExtendedCodeFormatter.lambda$applyPreparators$1 (ExtendedCodeFormatter.java:112)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept (ForEachOps.java:183)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:177)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1655)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:484)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential (ForEachOps.java:150)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential (ForEachOps.java:173)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach (ReferencePipeline.java:497)
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.ExtendedCodeFormatter.applyPreparators (ExtendedCodeFormatter.java:112)
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.ExtendedCodeFormatter.prepareWraps (ExtendedCodeFormatter.java:106)
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.DefaultCodeFormatter.prepareFormattedCode (DefaultCodeFormatter.java:231)
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.DefaultCodeFormatter.format (DefaultCodeFormatter.java:185)
    at io.spring.javaformat.eclipse.jdt.jdk11.internal.formatter.DefaultCodeFormatter.format (DefaultCodeFormatter.java:167)
    at io.spring.javaformat.formatter.Formatter.format (Formatter.java:127)
    at io.spring.javaformat.formatter.Formatter.format (Formatter.java:121)
    at io.spring.javaformat.formatter.Formatter.format (Formatter.java:98)
    at io.spring.javaformat.formatter.FileFormatter.formatFile (FileFormatter.java:119)
    at io.spring.javaformat.formatter.FileFormatter.lambda$formatFiles$1 (FileFormatter.java:96)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:195)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1655)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:484)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential (ForEachOps.java:150)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential (ForEachOps.java:173)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach (ReferencePipeline.java:497)
    at io.spring.format.maven.ApplyMojo.execute (ApplyMojo.java:54)
    at io.spring.format.maven.FormatMojo.execute (FormatMojo.java:137)
[...]

I am using version 0.0.41.

I attach the offending class (in a TGZ, due to GitHub restrictions).
unit.tgz

Thank you.

@philwebb philwebb changed the title NullPointerException when reformating Formatter throws NullPointerException when javadoc contains '@formatter:off' May 14, 2024
@philwebb philwebb added this to the 0.0.42 milestone May 14, 2024
@philwebb
Copy link
Contributor

Thanks for the sample. The root cause is the @formatter:off comment in the javadoc. The Eclipse formatter takes this as a signal to do no formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants