less4j icon indicating copy to clipboard operation
less4j copied to clipboard

OutOfMemoryError: Java heap space when compiling unwanted source maps

Open fnicollet opened this issue 7 years ago • 0 comments

Hello,

We are running into an error, here is the stack trace:

Caused by: java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Arrays.java:2367)
	at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
	at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415)
	at java.lang.StringBuilder.append(StringBuilder.java:132)
	at java.lang.StringBuilder.append(StringBuilder.java:179)
	at java.lang.StringBuilder.append(StringBuilder.java:72)
	at com.github.sommeri.sourcemap.SourceMapGeneratorV3.addValuesList(SourceMapGeneratorV3.java:367)
	at com.github.sommeri.sourcemap.SourceMapGeneratorV3.addSourceContentMap(SourceMapGeneratorV3.java:339)
	at com.github.sommeri.sourcemap.SourceMapGeneratorV3.appendTo(SourceMapGeneratorV3.java:314)
	at com.github.sommeri.less4j.core.output.SourceMapBuilder.toSourceMap(SourceMapBuilder.java:135)
	at com.github.sommeri.less4j.utils.CssPrinter.toSourceMap(CssPrinter.java:1052)
	at com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler.createCompilationResult(ThreadUnsafeLessCompiler.java:120)
	at com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler.doCompile(ThreadUnsafeLessCompiler.java:88)
	at com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler.compile(ThreadUnsafeLessCompiler.java:76)
	at com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler.compile(ThreadUnsafeLessCompiler.java:65)
	at com.github.sommeri.less4j.core.DefaultLessCompiler.compile(DefaultLessCompiler.java:44)
	at utils.applications.ThemeCompiler.compileThemeContent(ThemeCompiler.java:186)

We don't really care about source map, we don't actually have any, we are just compiling a lot of tiny less files. I tried disabling the source map altogether:

      LessCompiler.Configuration configuration = new LessCompiler.Configuration();
      configuration.getSourceMapConfiguration().setLinkSourceMap(false);
      LessCompiler.CompilationResult result = lessCompiler.compile(source, configuration);

But when I read the code, the option is read in "handleSourceMapLink": https://github.com/SomMeri/less4j/blob/bca5cb262c018f38ea8c58175df344c7d2345148/src/main/java/com/github/sommeri/less4j/core/ThreadUnsafeLessCompiler.java#L201

Which is right after the "toSourceMap" line where it crashes: https://github.com/SomMeri/less4j/blob/bca5cb262c018f38ea8c58175df344c7d2345148/src/main/java/com/github/sommeri/less4j/core/ThreadUnsafeLessCompiler.java#L177-L179

Is it an error in less4j? Should the option be read earlier so that it doesn't concatenate Strings that won't be used later?

Fabien

fnicollet avatar Mar 15 '17 09:03 fnicollet