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

SunReflectionFactoryInstantiator not working if parent class constructor isn't public #33

Closed
henri-tremblay opened this issue Apr 8, 2015 · 2 comments
Assignees
Milestone

Comments

@henri-tremblay
Copy link
Contributor

Original issue 30 created by henri-tremblay on 2014-12-13T13:20:34.000Z:

just found while adapting fast serialization (github) to android.

What steps will reproduce the problem?

  1. Create Externalizable ArrayList Subclass
  2. use objenesis new instance
  3. add an element to the arraylist subclass (=> exception)

What is the expected output? What do you see instead?
no excpetion

What version of the product are you using? On what operating system?
2.1

Please provide any additional information below.

the issue is, SunReflectionFactoryInstantiator always uses the "newConstructorForSerialization". However if there is public noarg constructor for an externalizable, this should be used instead (else initial state might be wrong).

@henri-tremblay
Copy link
Contributor Author

henri-tremblay commented Jul 1, 2015

That is the expected behavior. The SunReflectionFactorySerializationInstantiator will behave as wanted since it mimics the serialization instantiation.

However, SunReflectionFactoryInstantiator bypasses all constructors.

@henri-tremblay
Copy link
Contributor Author

There was indeed a bug related to SunReflectionFactorySerializationInstantiator. This instantiator should call the no-arg constructor of the first none-serializable parent class. If this constructor was not public, it would fail.

However, it is still normal that the constructor of the child class isn't called even though it implements Externalizable. Objenesis isn't following a full Java serialization process. It is only calling the no-arg constructor of the first none-serializable parent class. Nothing else. So if you want to detect Externalizable, you should do it in your own code.

@henri-tremblay henri-tremblay added this to the 2.6 milestone Jun 20, 2017
@henri-tremblay henri-tremblay changed the title Invalid object state for classes defining public default constructor SunReflectionFactoryInstantiator not working if parent class constructor isn't public Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant