I get cannot cast Object to Object groovy exception

1
0
-1

Hi,

I get this error:

Groovy script throws an exception of type class org.codehaus.groovy.runtime.typehandling.GroovyCastException with message = Cannot cast object 'hu.rate.jarkon.TetelEloiras@4bcb054d' with class 'hu.rate.jarkon.TetelEloiras' to class 'hu.rate.jarkon.TetelEloiras'

As you can see it cannot cast an object TetelEloiras to TetelEloiras, this is like if i have a Cat object and cannot cast to Cat. At least this is my first thought. What could cause such and error?

Edit: I have a groovy script class in my scripts, that class has a function that creates an instance of TetelEloiras and returns it filled with data, in the operations in a task i use this class and its function defined in the groovy script.

Regards

Zoltan

1 answer

1
+1
-1
This one is the BEST answer!

Hi Zoltan,

you can get these kind of issues when there are problems with the classpath.

Sometimes just restarting the tomcat server solves the issue (From the Studio click on "Server" tab and then "Restart web server")

If it doesn't work you can check if there are two copies of the same class incorrectly shared in the same classpath. This can also be a cause of error.

Regards,

Enrico

Comments

Submitted by kurucsai.zoltan... on Tue, 03/23/2021 - 13:12

Hi Enrico,

Thank you, but how could that happen? I mean how could i have problems with class path? Bonita should generate the entity classes, i am importing the classes of that Bonita generated.

If i had to guess it doesnt like the way i tried to create a reusable groovy script, i dont know how it uses external groovy scripts. My thought was that when i build the process the external script is merged with the script inside the operation script. That way the imports would be there two times, maybe that could cause this error? Because i dont upload my external groovy manually, it could only be there on the live server if the builded process contains it in some way. I dont know how Bonita engine uses these builded files, and how it builds.

But i think when i import the TetelEloiras in my main script it imports a package, and when i use the external script it will import the package again and this creates this error.

I will check if leaving out the import in the external groovy scipt works, and will reply.

Until then!

Zoltan

Submitted by enrico.curiotto on Tue, 03/23/2021 - 14:05

I just tried to create a new global groovy script, kind class. In the code I wrote:

class MyProxy { public String getData() { return "someData"; } }

Then in the process I created a groovy script in an operation with this code: MyProxy myProxy = new MyProxy(); return myProxy.getData()

Everything worked correctly without classpath issues. Cheers

Submitted by kurucsai.zoltan... on Tue, 03/23/2021 - 14:34

Hi,

I tried to create the same error locally, but it everything worked fine, maybe we need to restart our server. But it is still not the best if we need to constatly restart our server, it would be good to know the reason why this is happening.

Regards

Zoltan

Notifications