I get an java.lang.StackOverflowError
when I try to compile and package my code with mvn package
and Java 1.8.0_112.
My code compiles well with Java 7.
I tried to set JAVA_OPTS=-Xss512m
and tried with 1G as well but always get the same error.
The code is written in Scala and I am using these versions in my pom.xml:
<scala.version>2.10.4</scala.version>
<spark.version>1.6.0-cdh5.7.1</spark.version>
<hbase.version>1.2.0-cdh5.7.1</hbase.version>
<kafka.version>0.9.0.0</kafka.version>
<jackson.version>2.7.2</jackson.version>
<iodadm.version>05.4.1</iodadm.version>
I tried also with Scala version 2.12.0 because 2.10.x is not compatible with Java 8.
part of the error stack:
INFO] java.lang.reflect.InvocationTargetException
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] at scala_maven_executions.MainHelper.runMain(MainHelper.java:164)
[INFO] at scala_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26)
[ERROR] Caused by: java.lang.StackOverflowError
[INFO] at java.security.AccessController.doPrivileged(Native Method)
[INFO] at java.io.PrintWriter.<init>(PrintWriter.java:116)
[INFO] at java.io.PrintWriter.<init>(PrintWriter.java:100)
[INFO] at scala.reflect.api.Printers$class.render(Printers.scala:168)
[INFO] at scala.reflect.api.Universe.render(Universe.scala:59)
[INFO] at scala.reflect.api.Printers$class.show(Printers.scala:190)
One more thing, stackoverflow error is usually a runtime execution error, how is it possible to get it during compilation ?
[Added 1] I found that this error is caused by scala classes with at least 150 properties
[Added 2] The function throwing this error is equals function, i developed it like this:
def equals(other:MyClass):Boolean = {
this.P1 == other.P1 &&
this.P2 == other.P2 &&
... ~ 180 similar line ...
this.P180 == other.P180
}
Thank you.
I solved the problem by splitting the logical operation in many
def equals(other:MyClass):Boolean = {
Boolean bool1=this.P1 == other.P1 &&
this.P2 == other.P2 &&
...
this.P100 == other.P100
Boolean bool2=this.P101 == other.P101 &&
this.P102 == other.P102 &&
...
this.P200 == other.P200
bool1 && bool2
}
The approach to solve this type of problems is to compile the code gradually till finding the code bloc that throws the error
I hope this will help someone