Repository navigation
fix(gh-1330): allow reading kotlin collection types by default #1331
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
DarkAtra
wants to merge
3
commits into
nitrite:main
from
DarkAtra:gh-1330/allow-reading-kotlin-collection-types-by-default
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/SerialFilterRejectedException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright (c) 2017-2021 Nitrite author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.dizitart.no2.mvstore; | ||
|
|
||
| import org.h2.mvstore.MVStoreException; | ||
|
|
||
| import static org.h2.mvstore.DataUtils.ERROR_SERIALIZATION; | ||
|
|
||
| /** | ||
| * Thrown when a stored object is refused by the deserialization allowlist of | ||
| * {@link FilteredObjectDataType}. Unlike other serialization errors this is not | ||
| * a sign of a corrupt file, so the store must not roll back on it. It extends | ||
| * {@link MVStoreException} so that h2 passes it through instead of reporting | ||
| * the page as corrupt. | ||
| * | ||
| * @since 5.4.1 | ||
| */ | ||
| class SerialFilterRejectedException extends MVStoreException { | ||
| private static final long serialVersionUID = 1762953123L; | ||
|
|
||
| SerialFilterRejectedException(String message) { | ||
| super(ERROR_SERIALIZATION, message); | ||
| } | ||
|
|
||
| SerialFilterRejectedException(String message, Throwable cause) { | ||
| this(message); | ||
| initCause(cause); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...-native-tests/src/test/java/org/dizitart/nitrite/test/serialization/SerialFilterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package org.dizitart.nitrite.test.serialization; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import org.dizitart.nitrite.test.DatabaseTestUtils; | ||
| import org.dizitart.nitrite.test.serialization.model.UntrustedPayload; | ||
| import org.dizitart.no2.Nitrite; | ||
| import org.dizitart.no2.collection.Document; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class SerialFilterTest { | ||
|
|
||
| private static final String ALLOWED_CLASSES = "org.dizitart.nitrite.test.serialization.model.*"; | ||
|
|
||
| @Test | ||
| void rejectedClassShouldBeReportedWithoutRollback() throws IOException { | ||
|
|
||
| final Path databasePath = DatabaseTestUtils.getRandomDatabasePath(); | ||
|
|
||
| try (final Nitrite database = DatabaseTestUtils.openDatabase(databasePath, null)) { | ||
| // requires additional serialization hints for UntrustedPayload | ||
| // see: src/test/resources/META-INF/native-image/org.dizitart/nitrite-native-tests/serialization-config.json | ||
| database.getCollection("test").insert(Document.createDocument() | ||
| .put("payload", new UntrustedPayload("test"))); | ||
| } | ||
|
|
||
| // the error message is built from the rejected class (name and package), | ||
| // which has to work in native image as well | ||
| try (final Nitrite database = DatabaseTestUtils.openDatabase(databasePath, null)) { | ||
| assertThatThrownBy(() -> database.getCollection("test").find().toList()) | ||
| .hasStackTraceContaining("Class " + UntrustedPayload.class.getName() + " is not allowed") | ||
| .hasStackTraceContaining("allowedClasses(\"org.dizitart.nitrite.test.serialization.model.**\")"); | ||
| } | ||
|
|
||
| // a rejected class is no corruption, so the committed data must still be there | ||
| try (final Nitrite database = DatabaseTestUtils.openDatabase(databasePath, ALLOWED_CLASSES)) { | ||
|
|
||
| final var testCollection = database.getCollection("test"); | ||
|
|
||
| assertThat(testCollection.size()).isEqualTo(1); | ||
| final Document document = testCollection.find().firstOrNull(); | ||
| assertThat(document).isNotNull(); | ||
| assertThat(document.get("payload", UntrustedPayload.class).getValue()).isEqualTo("test"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void rejectedArrayShouldBeReportedByComponentType() throws IOException { | ||
|
|
||
| final Path databasePath = DatabaseTestUtils.getRandomDatabasePath(); | ||
|
|
||
| try (final Nitrite database = DatabaseTestUtils.openDatabase(databasePath, null)) { | ||
| // object arrays are only stored through java serialization when nested, e.g. in a list | ||
| final List<Object> payloads = new ArrayList<>(); | ||
| payloads.add(new UntrustedPayload[]{new UntrustedPayload("test")}); | ||
| database.getCollection("test").insert(Document.createDocument() | ||
| .put("payloads", payloads)); | ||
| } | ||
|
|
||
| // the message has to name the component type instead of the array type | ||
| try (final Nitrite database = DatabaseTestUtils.openDatabase(databasePath, null)) { | ||
| assertThatThrownBy(() -> database.getCollection("test").find().toList()) | ||
| .hasStackTraceContaining("Class " + UntrustedPayload.class.getName() + " is not allowed") | ||
| .hasStackTraceContaining("allowedClasses(\"org.dizitart.nitrite.test.serialization.model.**\")"); | ||
| } | ||
|
|
||
| try (final Nitrite database = DatabaseTestUtils.openDatabase(databasePath, ALLOWED_CLASSES)) { | ||
|
|
||
| final Document document = database.getCollection("test").find().firstOrNull(); | ||
|
|
||
| assertThat(document).isNotNull(); | ||
| final List<?> payloads = document.get("payloads", List.class); | ||
| assertThat(payloads).hasSize(1); | ||
| final UntrustedPayload[] array = (UntrustedPayload[]) payloads.get(0); | ||
| assertThat(array).hasSize(1); | ||
| assertThat(array[0].getValue()).isEqualTo("test"); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Identify process-wide filter rejections in the recovery guidance.
If the process-wide filter rejects a class,
createFilterrejects it before checkingallowedClasses. The message still directs the user toallowedClasses(...), which cannot resolve that rejection. Mention the process-wide filter as another policy to check, or record which filter rejected the class. (docs.oracle.com)🤖 Prompt for AI Agents