taoensso / nippy

The fastest serialization library for Clojure
https://www.taoensso.com/nippy
Eclipse Public License 1.0
1.04k stars 60 forks source link

GraalVM native-image fail when serializing Exception #129

Closed BrunoBonacci closed 4 years ago

BrunoBonacci commented 4 years ago

Hi,

I tried to use Nippy with a GraalVM compiled project and I stumbled into an issue. It seems that Nippy, when compiled via GraalVM, can't serialize Exceptions. Other data-types seems to work fine.

See the sample project here on how to reproduce the problem. https://github.com/BrunoBonacci/graalvm-clojure/tree/master/nippy

Do you have any idea why would that be the case?

ptaoussanis commented 4 years ago

Hi Bruno, not off hand- sorry!

But based on the error you're seeing:

Exception in thread "main" clojure.lang.ExceptionInfo: Unfreezable type: class clojure.lang.ExceptionInfo {:type clojure.lang.ExceptionInfo, :as-str "#error {\n :cause \"ExInfo\"\n :data {:data \"data\"}\n :via\n [{:type clojure.lang.ExceptionInfo\n :message \"ExInfo\"\n :data {:data \"data\"}}]\n :trace\n []}"}

Which comes from here, via here - I suspect that this util may be returning falsey.

I'd suggest experimenting a bit with the util to see precisely what the issue seems to be. Could be the util needs to be tweaked.

PRs welcome!

EDIT: As an alternative to figuring out why the Serializable fallback isn't working, you could probably also just add a specific freeze+thaw implementation for Exception or ExceptionInfo.

BrunoBonacci commented 4 years ago

I see, The reason it fails is because of this (Class/forName class-name) call here

By default, the native-image will throw a java.lang.ClassNotFoundException because of the close-world assumption. There are ways to hint that the class is already loaded via a special config (see here)

I will experiment a bit more to see if it can be solved via configuration only. thx

BrunoBonacci commented 4 years ago

So, after providing the correct Reflective config I get another error: com.oracle.svm.core.jdk.UnsupportedFeatureError: ObjectOutputStream.writeObject()

Which is due to the fact that serialization isn't supported yet: https://github.com/oracle/graal/issues/460

I will close this issue for the moment, as there is no general way to fix this. Thanks for your help.

FieryCod commented 2 years ago

This is fixed in GraalVM 21.3.0. @ptaoussanis would you like to accept the PR with the necessary configuration to support this?

See here

ptaoussanis commented 2 years ago

@FieryCod Would be happy to look at a PR, thanks Karol 👍