debugging "MyClass cannot be cast to MyClass" exceptions

175 views
Skip to first unread message

Brian Craft

unread,
Dec 6, 2014, 3:55:23 PM12/6/14
to clo...@googlegroups.com
I'm experimenting with jwrapper, and am getting runtime exceptions like this, due to some jar manipulation that it's doing. I know one of the steps is pack200, however running pack200 manually doesn't create these issues.

Anyone have suggestions for debugging this? I've seen this type of error countless times in clojure, but only when reloading interactively. This is the first time I've see it when running an uberjar.

juan.facorro

unread,
Dec 6, 2014, 5:02:01 PM12/6/14
to clo...@googlegroups.com
Hi Brian,

This problem usually happens when working on the REPL and you redefine a record or type (derecord and deftype), but there are still some existing instances lying around, that belong to the previous definition of that same type.


Cheers,

Juan

Brian Craft

unread,
Dec 6, 2014, 5:22:12 PM12/6/14
to clo...@googlegroups.com
Yes, I know. ;) In this case it's happening with an uberjar, not with the repl. I do "java -jar myapp.jar", and later, while it is processing data, get this exception. No repl involved.

Ambrose Bonnaire-Sergeant

unread,
Dec 7, 2014, 2:07:36 AM12/7/14
to clojure
Perhaps this issue is biting you http://dev.clojure.org/jira/browse/CLJ-979

Thanks,
Ambrose

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Craft

unread,
Dec 7, 2014, 2:46:01 PM12/7/14
to clo...@googlegroups.com, abonnair...@gmail.com
Not sure if I followed the non-interactive case. Is it just
1) deftype or defrecord in one file
2) import the class in a different file
3) AOT compile (e.g. uberjar)?

Brian Craft

unread,
Dec 8, 2014, 12:15:57 PM12/8/14
to clo...@googlegroups.com
Assuming this is something to do with class loaders going wrong, how would I approach finding the code paths involved? Could I identify where the class is being loaded; set breakpoints at those places to get the stack traces? Something else?

In my case it seems to be triggered by a type hint on a function argument that is a record.

Brian Craft

unread,
Dec 10, 2014, 12:22:14 AM12/10/14
to clo...@googlegroups.com
This exception is related to the pack200 -m option, which alters class file timestamps.

Do clojure class loaders depend on class file timestamps?

Laurent PETIT

unread,
Dec 10, 2014, 1:08:08 AM12/10/14
to clo...@googlegroups.com
Hello,

I think it does for deciding whether to use the class file found on disk, or to recompile the namespace in memory from the .clj file. 
Does the above make sense ?

Laurent 


--
Laurent Petit

Brian Craft

unread,
Dec 10, 2014, 12:16:11 PM12/10/14
to clo...@googlegroups.com
Oh! Yes, I think that's it. I didn't realize the uberjar would include source, which clojure would attempt to re-compile. I'm not sure why that would be useful in an uberjar.

I tried the lein :omit-source flag, which does indeed omit the source for my project, but still includes the source for all the dependencies, like clojure core libs. So I then get

java.lang.ClassCastException: clojure.core.VecNode cannot be cast to clojure.core.VecNode

and what-not. If I manually prune all the .clj from the zip file, then this exception goes away.

Is there some easier way to achieve this? Either tell clojure not to recompile, or tell lein not to include source from dependencies?

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Laurent Petit

Reply all
Reply to author
Forward
0 new messages