Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaSerialiazation error with primitive types #922

Closed
techexplorer0310 opened this issue Oct 7, 2022 · 3 comments · Fixed by #926
Closed

JavaSerialiazation error with primitive types #922

techexplorer0310 opened this issue Oct 7, 2022 · 3 comments · Fixed by #926

Comments

@techexplorer0310
Copy link

When we use JavaSerialization and if the object being serialized has primitive fields like int, char etc then we can ClassNotFoundException for int.class. Earlier ObjectInputStream was used to resolveClass which was handling this.
In the latest version ObjectInputStreamWithKryoClassLoader is used which does not handle this

To Reproduce
Use java serialization and read an object which has int field type.

Environment:

  • OS: All
  • JDK Version: 17
  • Kryo Version: 5.0
@theigl
Copy link
Collaborator

theigl commented Oct 30, 2022

@techexplorer0310: Could you please create reproducer for this issue?

@theigl
Copy link
Collaborator

theigl commented Nov 17, 2022

I briefly looked into this and it looks like that ObjectInputStreamWithKryoClassLoader should fall back on the default class loader instead of simply re-throwing the exception.

If you can't reproduce this issue in a simple test, could you register you own JavaSerializer that uses the following method to resolve class?

protected Class resolveClass (ObjectStreamClass type) {
	try {
		return Class.forName(type.getName(), false, kryo.getClassLoader());
	} catch (ClassNotFoundException ignored) {
		// ignored
	}
	try {
		return super.resolveClass(type);
	} catch (ClassNotFoundException ex) {
		throw new KryoException("Class not found: " + type.getName(), ex);
	} catch (IOException ex) {
		throw new KryoException("Could not load class: " + type.getName(), ex);
	}
}

theigl added a commit that referenced this issue Nov 17, 2022
theigl added a commit that referenced this issue Nov 17, 2022
theigl added a commit that referenced this issue Nov 21, 2022
@theigl
Copy link
Collaborator

theigl commented Nov 21, 2022

Should be fixed. Please verify against the latest SNAPSHOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants