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

ConfigurationProperties Not Populated Correctly In Native Image When Getter/Setter Name Is Different #33242

Closed
akefirad opened this issue Nov 17, 2022 · 3 comments
Assignees
Labels
status: duplicate A duplicate of another issue

Comments

@akefirad
Copy link

akefirad commented Nov 17, 2022

Specifically if the field has a different name than its getter/setter (real example io.awspring.cloud.autoconfigure.core.RegionProperties):

@ConfigurationProperties(prefix = RegionProperties.PREFIX)
public static class RegionProperties {

    public static final String PREFIX = "spring.cloud.aws.region";

    private String staticRegion;

    private boolean instanceProfile = false;

    public String getStatic() {
        return staticRegion;
    }

    public void setStatic(@Nullable String staticRegion) {
        this.staticRegion = staticRegion;
    }

    public boolean isInstanceProfile() {
        return this.instanceProfile;
    }

    public void setInstanceProfile(boolean instanceProfile) {
        this.instanceProfile = instanceProfile;
    }

    @Override
    public String toString() {
        return "RegionProperties{" +
                "staticRegion='" + staticRegion + '\'' +
                ", instanceProfile=" + instanceProfile +
                '}';
    }
}

With the following configuration:

spring:
  cloud:
    aws:
      region:
        static: eu-central-1
        static-region: us-east-1
        instance-profile: true

When loaded System.out.println(properties) prints:

RegionProperties{staticRegion='null', instanceProfile=true}

If you change the getter and setter to match the field name (i.e. getStaticRegion and setStaticRegion) the same configuration prints:

RegionProperties{staticRegion='us-east-1', instanceProfile=true}

I'm not sure what the root cause is or if it's a known limitation (Is there any documentation regarding known limitation apart from beta version?), neither do I know where is the right place to file the issue.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 17, 2022
@wilkinsona wilkinsona self-assigned this Nov 17, 2022
@wilkinsona
Copy link
Member

wilkinsona commented Nov 17, 2022

I can't reproduce this behaviour with either 3.0.0-RC2 or 3.0.0-SNAPSHOT:

$ build/native/nativeCompile/gh-33242

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v3.0.0-RC2)

2022-11-17T17:08:16.260Z  INFO 60407 --- [           main] com.example.gh33242.Gh33242Application   : Starting AOT-processed Gh33242Application using Java 17.0.5 with PID 60407 (/Users/awilkinson/Downloads/gh-33242/build/native/nativeCompile/gh-33242 started by awilkinson in /Users/awilkinson/Downloads/gh-33242)
2022-11-17T17:08:16.260Z  INFO 60407 --- [           main] com.example.gh33242.Gh33242Application   : No active profile set, falling back to 1 default profile: "default"
2022-11-17T17:08:16.265Z  INFO 60407 --- [           main] com.example.gh33242.Gh33242Application   : Started Gh33242Application in 0.013 seconds (process running for 0.022)
RegionProperties{staticRegion='eu-central-1', instanceProfile=true}

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Nov 17, 2022
@akefirad
Copy link
Author

akefirad commented Nov 17, 2022

OK, while preparing the sample project, I found the root cause. It is the additional isStatic method in the original RegionProperties class. Removing it resolves the issue. Adding getStaticRegion would also solve the issue, but only because the field becomes visible under the new name. I must have removed the isStatic method while cleaning up the code to paste it here. Sorry for the confusion. Here's the sample project. Let me know if you want to have it as a repo.
test-property-getter.zip

@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 Nov 17, 2022
@wilkinsona
Copy link
Member

wilkinsona commented Nov 17, 2022

Thanks, @akefirad. I've reproduced the problem now using 3.0.0-RC2. It doesn't occur with 3.0.0-SNAPSHOT due to, I believe, the changes made for #33232. I'll retitle and retag that issue to reflect the fact that it has fixed a bug.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2022
@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants