Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

How many fields does a class need to cause StackOverflowError with @ToString in Lombok

A: Around 568 (But sometimes it could be compile)

BeanWithSoManyFields.java · GitHub

This class causes java.lang.StackOverflowError like this:

java.lang.StackOverflowError
        at java.lang.reflect.Field.get(Field.java:393)
        at lombok.core.AST.buildWithField0(AST.java:383)
        at lombok.core.AST.buildWithField(AST.java:284)
        at lombok.javac.JavacAST.drill(JavacAST.java:357)
        at lombok.javac.JavacAST.buildStatementOrExpression(JavacAST.java:323)
        at lombok.javac.JavacAST.buildTree(JavacAST.java:183)
        at lombok.javac.JavacAST.buildTree(JavacAST.java:66)
        at lombok.core.AST.buildWithField0(AST.java:386)
        at lombok.core.AST.buildWithField(AST.java:284)
        at lombok.javac.JavacAST.drill(JavacAST.java:357)
  • You can compile this class with javac BeanWithSoManyFields.java -classpath c:\opt\pleiades\eclipse\lombok.jar if you had removed a field.

  • You can also increase the stack size of javac with -J-Xss option like javac BeanWithSoManyFields.java -J-Xss1025K -classpath c:\opt\pleiades\eclipse\lombok.jar.

  • @EqualsAndHashCode, @Getter, and @Setter do not cause StackOverflowError with this source.

  • Compiler embedded in Eclipse (ECJ) does not cause StackOverflowError with this source.