HtmlUnit / htmlunit-cssparser

CSS parser used by HtmlUnit
Apache License 2.0
5 stars 9 forks source link

Method too large: com/gargoylesoftware/css/parser/javacc/CSS3ParserTokenManager #4

Closed sepe81 closed 3 years ago

sepe81 commented 4 years ago

If you are using https://www.eclemma.org/jacoco/ for code analysis and the project under test uses htmlunit-cssparser then you get the following output during analysis.

[...]
Caused by: java.io.IOException: Error while instrumenting com/gargoylesoftware/css/parser/javacc/CSS3ParserTokenManager.
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrumentError(Instrumenter.java:159)
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:109)
    at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:92)
    ... 106 more
Caused by: org.jacoco.agent.rt.internal_43f5073.asm.MethodTooLargeException: Method too large: com/gargoylesoftware/css/parser/javacc/CSS3ParserTokenManager.jjMoveNfa_0 (II)I
    at org.jacoco.agent.rt.internal_43f5073.asm.MethodWriter.computeMethodInfoSize(MethodWriter.java:2087)
    at org.jacoco.agent.rt.internal_43f5073.asm.ClassWriter.toByteArray(ClassWriter.java:447)
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:90)
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:107)

If I get it right, CSS3ParserTokenManager is part of generated code (https://github.com/HtmlUnit/htmlunit-cssparser/blob/master/pom.xml#L65).

Would it be possible to restructure some part of the code generation to decrease the method size under 64K?

You can find a similar issue at https://stackoverflow.com/questions/37666076/jacoco-method-code-too-large-when-using-ver-0-7-6-and-0-7-5

alan-czajkowski commented 4 years ago

i have the same problem

java.lang.instrument.IllegalClassFormatException: Error while instrumenting com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes$Definition.
    at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:94)
    at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
    at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
    at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
...
Caused by: java.io.IOException: Error while instrumenting com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes$Definition.
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrumentError(Instrumenter.java:159)
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:109)
    at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:92)
...
Caused by: org.jacoco.agent.rt.internal_43f5073.asm.MethodTooLargeException: Method too large: com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes$Definition.<clinit> ()V
    at org.jacoco.agent.rt.internal_43f5073.asm.MethodWriter.computeMethodInfoSize(MethodWriter.java:2087)
    at org.jacoco.agent.rt.internal_43f5073.asm.ClassWriter.toByteArray(ClassWriter.java:447)
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:90)
    at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:107)
rbri commented 4 years ago

The code is generated by javacc and i see no real chance to make the code smaller. But on the other hand i also see no real need for a project to instrument the code - why not excluding the cssparser?

sepe81 commented 3 years ago

Ok, thank you. I try to exclude it.

alan-czajkowski commented 3 years ago

@sepe81 did an exclusion work? if so, can you please show how you excluded?

sepe81 commented 3 years ago

@alan-czajkowski The following exclusion worked:

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>com/gargoylesoftware/**</exclude>
                </excludes>
            </configuration>
        </plugin>
revusky commented 1 year ago

This problem has been resolved in JavaCC 21. See: https://javacc.com/2021/03/30/code-too-large-problem-fixed/

jonathansp commented 7 months ago

@sepe81 how would you achieve the same using gradle?

alan-czajkowski commented 7 months ago

@jonathansp this might help: https://www.baeldung.com/jacoco-report-exclude

but I strongly recommend moving away from Gradle to Maven