Skip to content

OutOfMemoryError: Java heap space when compiling unwanted source maps #362

@fnicollet

Description

@fnicollet

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":

if (!sourceMapConfiguration.shouldLinkSourceMap() && !sourceMapConfiguration.isInline())

Which is right after the "toSourceMap" line where it crashes:

String sourceMap = builder.toSourceMap();
handleSourceMapLink(cssStyleSheet, css, options, lessSource, sourceMap);

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions