Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

ConstructorArgumentValues should only be assigned when indexed argument values are present #1403

Closed
AzarguNazari opened this issue Dec 24, 2021 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@AzarguNazari
Copy link

As I was running spring native (0.11.1) with the following dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>something</groupId>
    <artifactId>project</artifactId>
    <version>1.1.0</version>
    <name>project</name>

    <properties>
        <java.version>17</java.version>
        <repackage.classifier/>
        <spring-cloud.version>2021.0.0</spring-cloud.version>
        <spring-native.version>0.11.1</spring-native.version>
        <spring-plugin-metadata.version>2.0.0.RELEASE</spring-plugin-metadata.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.plugin</groupId>
            <artifactId>spring-plugin-metadata</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.experimental</groupId>
            <artifactId>spring-native</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.plugin</groupId>
                <artifactId>spring-plugin-metadata</artifactId>
                <version>${spring-plugin-metadata.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.experimental</groupId>
                <artifactId>spring-native</artifactId>
                <version>${spring-native.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>${repackage.classifier}</classifier>
                    <image>
                        <builder>paketobuildpacks/builder:tiny</builder>
                        <env>
                            <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                        </env>
                    </image>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.experimental</groupId>
                <artifactId>spring-aot-maven-plugin</artifactId>
                <version>${spring-native.version}</version>
                <executions>
                    <execution>
                        <id>test-generate</id>
                        <goals>
                            <goal>test-generate</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <profiles>
        <profile>
            <id>native</id>
            <properties>
                <repackage.classifier>exec</repackage.classifier>
                <native-buildtools.version>0.9.9</native-buildtools.version>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-launcher</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>${native-buildtools.version}</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>test-native</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>build-native</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

I was getting the following error

native-image-problem

@AzarguNazari AzarguNazari changed the title Spring Cloud Native image has error while doing AOT Spring Cloud AOT generates error classes while doing AOT using native image Dec 24, 2021
@AzarguNazari AzarguNazari changed the title Spring Cloud AOT generates error classes while doing AOT using native image Spring Cloud AOT generates class with error while doing AOT using native image Dec 24, 2021
@AzarguNazari AzarguNazari changed the title Spring Cloud AOT generates class with error while doing AOT using native image Spring Cloud AOT generates class with error while creating native image Dec 24, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 24, 2021
@snicoll
Copy link
Contributor

snicoll commented Dec 26, 2021

@AzarguNazari Spring Cloud Stream isn't supported but that error is unrelated. Can you share a bit more detail about this bean?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Dec 26, 2021
@AzarguNazari
Copy link
Author

The error which you see in the picture is from the generated AOT classes on the target directory. The application runs fine without doing the AOT, but when the process of AOT happens, the generated optimized file shows this error.

@snicoll
Copy link
Contributor

snicoll commented Dec 30, 2021

Yes I understood that already and I am afraid a screenshot is nowhere near enough information. Can you please share more information? If you can build a small sample we can run that would be ideal.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 4, 2022
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jan 5, 2022
@snicoll
Copy link
Contributor

snicoll commented Jan 5, 2022

I think I got it in the meantime. Looking at the screenshot and the code, it looks like this bean only has generic argument values (and no indexed values at all). We support the latter only which is why we start writing some code and then stop which leads to the compilation failure.

@snicoll snicoll changed the title Spring Cloud AOT generates class with error while creating native image ConstructorArgumentValues should only be assigned when indexed argument values are present Jan 5, 2022
@snicoll snicoll added theme: aot type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: waiting-for-feedback We need additional information before we can continue labels Jan 5, 2022
@snicoll snicoll added this to the 0.11.2 milestone Jan 5, 2022
@snicoll snicoll self-assigned this Jan 5, 2022
@snicoll snicoll closed this as completed in f5b40f2 Jan 5, 2022
@snicoll
Copy link
Contributor

snicoll commented Jan 5, 2022

@AzarguNazari note that this fix won't change your particular situation. Spring Cloud Stream isn't supported and neither are generic constructor argument values. But at least the generated code won't be invalid now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

3 participants