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

ClassCastException on element update #1093

Closed
Srdjan-V opened this issue Dec 29, 2024 · 2 comments · Fixed by #1105
Closed

ClassCastException on element update #1093

Srdjan-V opened this issue Dec 29, 2024 · 2 comments · Fixed by #1105
Assignees
Labels

Comments

@Srdjan-V
Copy link

Srdjan-V commented Dec 29, 2024

If a repository gets open by clearing it, the type of the db will stay Object causing class cast exceptions while deserializing.

    @Data
    @Entity
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TestEntity {
        @Id
        String name;
        String data;
    }

    @Test
    void execute() {
        File file = new File(FileUtils.getTempDirectory(), "db_test");
        file.deleteOnExit();

        RocksDBModule storeModule = RocksDBModule.withConfig()
                .filePath(file)
                .build();

        JacksonMapper jacksonMapper = new JacksonMapper() {
            @Override protected <Target> Target convertFromDocument(Document source, Class<Target> type) {
                try {
                    return super.convertFromDocument(source, type);
                } catch (IllegalArgumentException | ObjectMappingException e) {
                    return null;
                }
            }
        };
        for (Module jacksonModule : List.of(
                new ParameterNamesModule(),
                new Jdk8Module(),
                new JavaTimeModule())) {
            jacksonMapper.registerJacksonModule(jacksonModule);
        }

        Nitrite nitrite = Nitrite.builder()
                .loadModule(storeModule)
                .loadModule(NitriteModule.module(jacksonMapper))
                .openOrCreate();


        ObjectRepository<TestEntity> repository = nitrite.getRepository(TestEntity.class, "K");

        // this will open a NitriteMap<Object, Object>
        repository.clear();
        
        repository = nitrite.getRepository(TestEntity.class, "K");
        repository.update(new TestEntity("SS", "S"), true);
        repository.update(new TestEntity("SS", "S"), true);
    }
class java.lang.Object cannot be cast to class java.util.List (java.lang.Object and java.util.List are in module java.base of loader 'bootstrap')
java.lang.ClassCastException: class java.lang.Object cannot be cast to class java.util.List (java.lang.Object and java.util.List are in module java.base of loader 'bootstrap')
	at org.dizitart.no2.index.SingleFieldIndex.addIndexElement(SingleFieldIndex.java:145)
	at org.dizitart.no2.index.SingleFieldIndex.write(SingleFieldIndex.java:73)
	at org.dizitart.no2.index.ComparableIndexer.writeIndexEntry(ComparableIndexer.java:70)
	at org.dizitart.no2.collection.operation.DocumentIndexWriter.writeIndexEntryInternal(DocumentIndexWriter.java:97)
	at org.dizitart.no2.collection.operation.DocumentIndexWriter.writeIndexEntry(DocumentIndexWriter.java:50)
	at org.dizitart.no2.collection.operation.WriteOperations.insert(WriteOperations.java:99)
	at org.dizitart.no2.collection.operation.WriteOperations.update(WriteOperations.java:204)
	at org.dizitart.no2.collection.operation.CollectionOperations.update(CollectionOperations.java:102)
	at org.dizitart.no2.collection.DefaultNitriteCollection.update(DefaultNitriteCollection.java:125)
	at org.dizitart.no2.repository.DefaultObjectRepository.update(DefaultObjectRepository.java:129)
	at org.dizitart.no2.repository.DefaultObjectRepository.update(DefaultObjectRepository.java:118)
	at io.github.srdjanv.Testdb.execute(TestApp.java:87)
@Srdjan-V
Copy link
Author

Srdjan-V commented Jan 5, 2025

Any updates on this?

@anidotnet anidotnet self-assigned this Jan 23, 2025
@anidotnet anidotnet added the bug label Jan 23, 2025
@anidotnet anidotnet moved this from To Do to In Progress in Nitrite 4.x Development Jan 23, 2025
anidotnet added a commit that referenced this issue Jan 23, 2025
@anidotnet anidotnet linked a pull request Jan 23, 2025 that will close this issue
@coderabbitai coderabbitai bot mentioned this issue Jan 23, 2025
anidotnet added a commit that referenced this issue Jan 23, 2025
* fixes #1093

* build fix
@github-project-automation github-project-automation bot moved this from In Progress to Done in Nitrite 4.x Development Jan 23, 2025
@anidotnet
Copy link
Contributor

anidotnet commented Jan 26, 2025

The recent snapshot version has the fix for this issue.

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

Successfully merging a pull request may close this issue.

2 participants