Problem
Running a JUnit test with Run with Coverage in IntelliJ IDEA fails when the coverage agent tries to instrument a large class. The class is not loaded, the test fails, and an entry is written to coverage-error.log:
[Coverage]: Error during class instrumentation: <fully.qualified.ClassName>
java.lang.RuntimeException: Class file too large!
at org.jetbrains.asm4.ClassWriter.toByteArray(Unknown Source)
at com.intellij.rt.coverage.instrumentation.Instrumentator.instrument(Instrumentator.java:164)
...
The same test passes when the run configuration is executed without coverage.
Cause
The IntelliJ coverage agent instruments bytecode by inserting probes at every branch and line. For methods already close to the JVM per-method size limit of 64 KB, the added probes push the method past that limit. The ASM ClassWriter then throws Class file too large!, and the affected class is not defined by the class loader.
The reported trigger class is org.sqlite.SQLite from the SQLite JDBC driver. Any generated or hand-written class with large methods (parsers, protocol buffers, embedded resource tables, generated grammars) can reach the same limit.
Resolution
Exclude the affected class from coverage instrumentation.
- Open Run | Edit Configurations and select the failing test configuration.
- Click Modify options.
- Under the Code Coverage group, select Exclude classes and packages.
- Add a pattern for the class or its package. For example,
org.sqlite.*. - Re-run the configuration with coverage.
Coverage is not collected for excluded classes. The rest of the run is unaffected.
Comments
0 comments
Please sign in to leave a comment.