From cdf3767c4615dee57abcacae76feba36b4d360a9 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 1 Oct 2024 12:40:52 +0200 Subject: [PATCH] Fixed NPE in EclipseSerializerRegisteringCopier --- CHANGELOG.md | 4 + docs/antora.yml | 6 +- .../EclipseSerializerRegisteringCopier.java | 4 + .../integration/isolated/tests/id/IdTest.java | 41 ++++++++++ .../CustomerWithIdStringNoAutoGenerate.java | 78 +++++++++++++++++++ ...rWithIdStringNoAutoGenerateRepository.java | 24 ++++++ .../shared/tests/SimpleSingleTest.java | 11 +++ 7 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerate.java create mode 100644 spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerateRepository.java diff --git a/CHANGELOG.md b/CHANGELOG.md index a053118e..bc724225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.2.2 + +* Fixed NPE in EclipseSerializerRegisteringCopier + # 2.2.1 * Fixed release version diff --git a/docs/antora.yml b/docs/antora.yml index ef2dbe97..0a7532f4 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -1,14 +1,14 @@ name: ROOT title: Spring-Data-Eclipse-Store version: master -display_version: '2.2.1' +display_version: '2.2.2' start_page: index.adoc nav: - modules/ROOT/nav.adoc asciidoc: attributes: product-name: 'Spring-Data-Eclipse-Store' - display-version: '2.2.1' - maven-version: '2.2.1' + display-version: '2.2.2' + maven-version: '2.2.2' page-editable: false page-out-of-support: false diff --git a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/registering/EclipseSerializerRegisteringCopier.java b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/registering/EclipseSerializerRegisteringCopier.java index 608110ba..9d7f7469 100644 --- a/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/registering/EclipseSerializerRegisteringCopier.java +++ b/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/registering/EclipseSerializerRegisteringCopier.java @@ -134,6 +134,10 @@ private T copy(final T source, final PersistenceManager persistenceM loader.iterateEntries( (id, copiedObject) -> { + if(copiedObject == null) + { + return; + } if(copiedObject != null && !this.supportedChecker.isSupported(copiedObject.getClass())) { throw new DataTypeNotSupportedException(copiedObject.getClass()); diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/IdTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/IdTest.java index fd216e61..9aed0ad0 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/IdTest.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/IdTest.java @@ -40,6 +40,8 @@ import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdLong; import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdLongRepository; import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdString; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdStringNoAutoGenerate; +import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdStringNoAutoGenerateRepository; import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdStringRepository; import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdUuid; import software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model.CustomerWithIdUuidRepository; @@ -136,6 +138,45 @@ void saveBulkWithAutoIdIntAndHardcodedId(@Autowired final CustomerWithIdIntRepos ); } + @Test + void saveBulkWithNoAutoIdIntSameId( + @Autowired final CustomerWithIdIntegerNoAutoGenerateRepository customerRepository) + { + final CustomerWithIdIntegerNoAutoGenerate customer1 = + new CustomerWithIdIntegerNoAutoGenerate(1, TestData.FIRST_NAME, TestData.LAST_NAME); + final CustomerWithIdIntegerNoAutoGenerate customer2 = + new CustomerWithIdIntegerNoAutoGenerate(1, TestData.FIRST_NAME, TestData.LAST_NAME); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> customerRepository.saveAll(List.of(customer1, customer2)) + ); + } + + @Test + void saveBulkWithNoAutoIdStringSameId( + @Autowired final CustomerWithIdStringNoAutoGenerateRepository customerRepository) + { + final CustomerWithIdStringNoAutoGenerate customer1 = + new CustomerWithIdStringNoAutoGenerate("1", TestData.FIRST_NAME, TestData.LAST_NAME); + final CustomerWithIdStringNoAutoGenerate customer2 = + new CustomerWithIdStringNoAutoGenerate("1", TestData.FIRST_NAME, TestData.LAST_NAME); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> customerRepository.saveAll(List.of(customer1, customer2)) + ); + } + + @Test + void saveBulkWithNoAutoIdStringDifferentId( + @Autowired final CustomerWithIdStringNoAutoGenerateRepository customerRepository) + { + final CustomerWithIdStringNoAutoGenerate customer1 = + new CustomerWithIdStringNoAutoGenerate("1", TestData.FIRST_NAME, TestData.LAST_NAME); + final CustomerWithIdStringNoAutoGenerate customer2 = + new CustomerWithIdStringNoAutoGenerate("2", TestData.FIRST_NAME, TestData.LAST_NAME); + Assertions.assertDoesNotThrow(() -> customerRepository.saveAll(List.of(customer1, customer2))); + } + /** * In other tests {@link EclipseStoreStorage#clearData} is called. Here the datastore is restarted again to ensure * no previous method is called before the test. diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerate.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerate.java new file mode 100644 index 00000000..34f1b4b7 --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerate.java @@ -0,0 +1,78 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * 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 software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model; + +import java.util.Objects; + +import jakarta.persistence.Id; + + +public class CustomerWithIdStringNoAutoGenerate +{ + @Id + private String id; + + private final String firstName; + private final String lastName; + + public CustomerWithIdStringNoAutoGenerate(final String id, final String firstName, final String lastName) + { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() + { + return this.firstName; + } + + public String getLastName() + { + return this.lastName; + } + + @Override + public String toString() + { + return String.format( + "Customer[firstName='%s', lastName='%s']", + this.firstName, this.lastName); + } + + @Override + public boolean equals(final Object o) + { + if(this == o) + { + return true; + } + if(o == null || this.getClass() != o.getClass()) + { + return false; + } + final CustomerWithIdStringNoAutoGenerate customer = (CustomerWithIdStringNoAutoGenerate)o; + return Objects.equals(this.firstName, customer.firstName) && Objects.equals( + this.lastName, + customer.lastName); + } + + @Override + public int hashCode() + { + return Objects.hash(this.firstName, this.lastName); + } +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerateRepository.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerateRepository.java new file mode 100644 index 00000000..a59538fe --- /dev/null +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/model/CustomerWithIdStringNoAutoGenerateRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2024 XDEV Software (https://xdev.software) + * + * 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 software.xdev.spring.data.eclipse.store.integration.isolated.tests.id.model; + +import org.springframework.data.repository.CrudRepository; + + +public interface CustomerWithIdStringNoAutoGenerateRepository + extends CrudRepository +{ +} diff --git a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleSingleTest.java b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleSingleTest.java index 4052eeef..7aa33866 100644 --- a/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleSingleTest.java +++ b/spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/shared/tests/SimpleSingleTest.java @@ -15,6 +15,7 @@ */ package software.xdev.spring.data.eclipse.store.integration.shared.tests; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -130,6 +131,16 @@ void testNullSaveAll() Assertions.assertThrows(IllegalArgumentException.class, () -> this.repository.saveAll(null)); } + @Test + void testNullSaveAllWithList() + { + final Customer customer = new Customer(TestData.FIRST_NAME, TestData.LAST_NAME); + final List listWithNullElement = new ArrayList<>(); + listWithNullElement.add(customer); + listWithNullElement.add(null); + Assertions.assertDoesNotThrow(() -> this.repository.saveAll(listWithNullElement)); + } + @Test void testBasicSaveAndFindAll() {