google-java-format
google-java-format copied to clipboard
OutOfMemoryError on formating file with no actual code
Hi,
seems like I found an indentation bomb. Happend to try to format OdfManifestSaxHandler.java (Rev: 1869391) and always failed with OutOfMemoryError (tried up to 12G of heap space). Original file is 6 kB. Output of formatter would be approximately 3 GB. Smaller test case which could be handled would be
Input:
class X {
*//** javadoc *//*
public void foo(Bar bar) {}
*//** javadoc *//*
public void foo(Bar bar) {}
*//** javadoc *//*
public void foo(Bar bar) {}
*//** javadoc *//*
public void foo(Bar bar) {}
}*/
Output (each # represents 100 space characters):
class X {
*//** javadoc *//*
public void foo(Bar bar) {}
*//** javadoc *//*
public void foo(Bar bar) {}
*//**
# * javadoc
# *//*
## public void foo(Bar bar) {}
## *//**
#### * javadoc
#### *//*
######## public void foo(Bar bar) {}
######## }*/
I can't reproduce with your test input:
$ java -jar google-java-format-1.7-all-deps.jar X.java
X.java:2:10: error: illegal start of type
X.java:5:10: error: illegal start of type
X.java:8:10: error: illegal start of type
X.java:11:10: error: illegal start of type
X.java:13:3: error: class, interface, or enum expected
Can you provide more detailed repro instructions? Which version of google-java-format are you using?
@eaftan the described issue is amplified as the number of commented-out sections increases. Reproduction using the linked OdfManifestSaxHandler:
$ java -jar google-java-format-1.7-all-deps.jar OdfManifestSaxHandler.java
OdfManifestSaxHandler.java: error: Java heap space
java.lang.OutOfMemoryError: Java heap space
at org.openjdk.tools.javac.parser.UnicodeReader.getRawCharacters(UnicodeReader.java:259)
at org.openjdk.tools.javac.parser.JavadocTokenizer.getLineMap(JavadocTokenizer.java:467)
at org.openjdk.tools.javac.parser.Scanner.getLineMap(Scanner.java:127)
at org.openjdk.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:3200)
at com.google.googlejavaformat.java.RemoveUnusedImports.parse(RemoveUnusedImports.java:247)
at com.google.googlejavaformat.java.RemoveUnusedImports.removeUnusedImports(RemoveUnusedImports.java:211)
at com.google.googlejavaformat.java.FormatFileCallable.fixImports(FormatFileCallable.java:52)
at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:46)
at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:26)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
I can't reproduce with your test input:
Sorry, somehow the first line got lost. It containted the start tag for a comment: /*
/*
class X {
*//** javadoc *//*
public void foo(Bar bar) {}
*//** javadoc *//*
public void foo(Bar bar) {}
*//** javadoc *//*
public void foo(Bar bar) {}
*//** javadoc *//*
public void foo(Bar bar) {}
}*/
It fails for 1.7 and on master.