mapstruct-examples icon indicating copy to clipboard operation
mapstruct-examples copied to clipboard

mapstruct-protobuf3 use lombok:UnsupportedOperationException(Collections$UnmodifiableCollection)

Open minzhiwu opened this issue 2 years ago • 0 comments

modify mapstruct-protobuf3/usage/pom.xml plugin config,

                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${org.mapstruct.version}</version>
                    </path>

                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${org.projectlombok.version}</version>
                    </path>

                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok-mapstruct-binding</artifactId>
                        <version>${lombok-mapstruct-binding.version}</version>
                    </path>

                    <path>
                        <!-- Add your SPI implementation. -->
                        <groupId>org.mapstruct.examples.spi</groupId>
                        <artifactId>protobuf-spi-impl</artifactId>
                        <version>1.0.0</version>
                    </path>

                </annotationProcessorPaths>
   `

rebuild the mapstruct-protobuf3, run the test,report an error java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableCollection.addAll(Collections.java:1065) at org.mapstruct.example.mapper.UserMapperImpl.map(UserMapperImpl.java:34) at org.mapstruct.example.ProtobufTest.test(ProtobufTest.java:33),

Partially generated code

if ( userDTO.getMainDepartmentsList() != null ) {
           List<UserProtos.DepartmentDTO> list = departmentListToDepartmentDTOList( user.getMainDepartments() );
            if ( list != null ) {
                userDTO.getMainDepartmentsList().addAll( list );
            }

        }
        if ( userDTO.getDepartmentsList() != null ) {

            List<UserProtos.DepartmentDTO> list1 = departmentListToDepartmentDTOList( user.getDepartments() );
            if ( list1 != null ) {
                userDTO.getDepartmentsList().addAll( list1 );
            }

recover mapstruct-protobuf3/usage/pom.xml plugin config, run test success. Is there any way to solve this problem?

minzhiwu avatar Oct 25 '22 02:10 minzhiwu