8000 TypeCastException for Root object when spring-boot-devtools dependency available classpath/runtime · Issue #150 · eclipse-store/store · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TypeCastException for Root object when spring-boot-devtools dependency available classpath/runtime #150

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

Closed
manideeps opened this issue Feb 22, 2024 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@manideeps
Copy link
manideeps commented Feb 22, 2024

Environment Details

  • EclipseStore Version: integrations-spring-boot3 : 1.2.0
  • JDK version: 21
  • OS: Mac
  • Used frameworks: Spring

Describe the bug

EmbeddedStorageManager creation failed due to TypeCastException for root object. This happens only when spring-boot-devtools dependency is present.

If spring-boot-devtools depedency removed, its works fine. Not sure, this has to be reported to eclipse serializer project

### StackTrace:
Caused by: org.eclipse.serializer.exceptions.TypeCastException: Cannot cast com.deepak.storedemokotlin.Data to com.deepak.storedemokotlin.Data
	at org.eclipse.serializer.persistence.binary.types.AbstractBinaryHandlerReflective.updateState(AbstractBinaryHandlerReflective.java:539)
	at org.eclipse.serializer.persistence.binary.types.AbstractBinaryHandlerReflective.updateState(AbstractBinaryHandlerReflective.java:44)
	at org.eclipse.serializer.persistence.binary.types.BinaryLoader$Default.buildInstances(BinaryLoader.java:462)
	at org.eclipse.serializer.persistence.binary.types.BinaryLoader$Default.build(BinaryLoader.java:396)
	at org.eclipse.serializer.persistence.binary.types.BinaryLoader$Default.get(BinaryLoader.java:828)
	at org.eclipse.serializer.persistence.binary.types.BinaryLoader$Default.loadRoots(BinaryLoader.java:872)
	at org.eclipse.store.storage.embedded.types.EmbeddedStorageManager$Default.loadExistingRoots(EmbeddedStorageManager.java:349)
	at org.eclipse.store.storage.embedded.types.EmbeddedStorageManager$Default.initialize(EmbeddedStorageManager.java:372)
	at org.eclipse.store.storage.embedded.types.EmbeddedStorageManager$Default.start(EmbeddedStorageManager.java:252)
	at org.eclipse.store.storage.embedded.types.EmbeddedStorageManager$Default.start(EmbeddedStorageManager.java:95)
	at org.eclipse.store.integrations.spring.boot.types.EclipseStoreProviderImpl.createStorage(EclipseStoreProviderImpl.java:59)
	at org.eclipse.store.integrations.spring.boot.types.EclipseStoreProviderImpl.createStorage(EclipseStoreProviderImpl.java:50)
	at org.eclipse.store.integrations.spring.boot.types.EclipseStoreBeanFactory.embeddedStorageManager(EclipseStoreBeanFactory.java:59)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140)


@manideeps manideeps changed the title Getting TypeCastException for Root object when spring-boot-devtools dependency available classpath/runtime TypeCastException for Root object when spring-boot-devtools dependency available classpath/runtime Feb 22, 2024
@zdenek-jonas
Copy link
Contributor
zdenek-jonas commented Feb 22, 2024

Do you create your own embedded manager or is injected by Spring? Could you prepare some repository, to see, what are you doing and help us to identify the problem?

In general, the issue is that with dev tools, the classes are loaded by a different class loader than the default one.
Therefore, I need to know exactly what you are doing and how you are using it, so I can assess whether it is an error in our code or incorrect usage.

@manideeps
Copy link
Author
manideeps commented Feb 22, 2024

I used the storage manager created by spring. But Issue occurs for own embedded manager as-well. Repo is - https://github.com/manideeps/eclipsestore-sample

@manideeps
Copy link
Author

There is no issue when app starting for first time or with empty storage directory. But from next time when eclipsestore loading existing from storage directory or root object , its throws TypeCastException

@zdenek-jonas
Copy link
Contributor
zdenek-jonas commented Feb 22, 2024

Thank you for providing us with the demo. I can confirm that this is a bug.
We are now working on the new Spring Integration, we will fix it together.

@zdenek-jonas zdenek-jonas added the bug Something isn't working label Feb 22, 2024
@zdenek-jonas zdenek-jonas self-assigned this Feb 22, 2024
@zdenek-jonas
Copy link
Contributor

The reason for this problem is, that the Root object is created with another classloader als application context classloader.

This must be fixed.

@manideeps
as temporary workaround, disable root in configuration and created it manually for the first time:

@SpringBootApplication
@Import(EclipseStoreSpringBoot.class)
public class StoredemoApplication {

  public static void main(String[] args) {
    ConfigurableApplicationContext context = SpringApplication.run(StoredemoApplication.class, args);
    StorageManager manager = context.getBean(StorageManager.class);
    Object root = manager.root();

    if (root == null) {
      root = new Data();
      manager.setRoot(root);
      manager.storeRoot();
    }

    if (root instanceof Data data){
      System.out.println("Welcome---"+data.getWelcomeText());
      System.out.println("Root is data");
      data.setWelcomeText(data.getWelcomeText()+"-append--"+"welcome again");
      manager.storeRoot();
    }else {
      System.out.println("Root is not data");
    }

  }

}

@zdenek-jonas
Copy link
Contributor

It will be fixed with this PR:
#136

@fschon
Copy link
fschon commented Mar 1, 2024

Can you explain in a little more detail on how to get this workaround working please.

See also my question with code at: #158

I have commented out the data root in application.properties and modified the main() as per your code above, but now get an error:

Caused by: java.lang.NullPointerException: Cannot invoke "com.example.data.DataRoot.emails()" because the return value of "com.example.data.Emails.dataRoot()" is null

@hg-ms
Copy link
Contributor
hg-ms commented Mar 4, 2024

Hello fschon,

Did you try to delete the storage after doing the modifications of your code?
The exception you posted indicates that the stored root is null.
The workaround manually creates a new Root object if it’s null and then sets the root element and stores it:

if (root == null) {
   root = new Data();
   manager.setRoot(root);
   manager.storeRoot();
}

Looking at you code in #158 I found another problem in the ‘Emails.save(String email) method’ :
This methods calls the store on the passed String but not on the List the String is added. This way the modification of the Emails list is not persisted and, after reloading the storage, the Emails list does not contain the added email.
You need to store the list storageManager.store(dataRoot().emails()). The added email will then be stored implicitly if it is not already stored. (see https://docs.eclipsestore.io/manual/storage/storing-data/lazy-eager-full.html for details)

@amagnolo
Copy link

This bug was driving me crazy!
Since spring-boot-devtools is enabled by default in Vaadin, this is probably turning away most Vaadin users who saw the EclipseStore webinar and wanted to give it a try.
You should at least mention in the 1.2 documentation that the solution to TypeCastException is to either remove org.eclipse.store.root from application.properties or spring-boot-devtools from the dependencies (or wait for next release with the fix).

@zdenek-jonas
Copy link
Contributor

The version 1.3.1 has been released. Please test it again, if any problems occurs, just reopen this issue.

@noisymark
Copy link
noisymark commented May 27, 2024

Bug still present in 1.3.2

EDIT: Bug is indeed resolved by removing devTools dependency from Spring Boot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants
0