Hi,

I have some configuration properties class which has Map<String, Integer> field. Key in map can contain * for some ant path matching. If property source contains that keys, binder will bind them without * characters and with unexpected values also.

Here is minimal sample to reproduce this:

static class DemoConfigurationProperties {

    private Map<String, Integer> properties = Map.of("foo-*", 1, "*-foo", 2, "*-foo-*", 3);

    public Map<String, Integer> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, Integer> properties) {
        this.properties = properties;
    }
}

/**
 * Tis test fails with:
 * AssertionFailedError:
 * Expected :{foo-*=4, *-foo-*=6, *-foo=5}
 * Actual   :{foo-*=1, *-foo-*=3, *-foo=2, -foo-=6, foo-=6, -foo=6}
 */
@Test
public void testWithSameProperties() {
    DemoConfigurationProperties demoConfigurationProperties = new DemoConfigurationProperties();
    Assertions.assertEquals(Map.of("foo-*", 1, "*-foo", 2, "*-foo-*", 3), demoConfigurationProperties.getProperties());

    // now bind same properties
    StandardEnvironment environment = new StandardEnvironment();
    Map<String, Object> properties = Map.of("demo.properties.foo-*", 4, "demo.properties.*-foo", 5, "demo.properties.*-foo-*", 6);
    environment.getPropertySources().addFirst(new MapPropertySource("demo-map-source", properties));
    Binder.get(environment).bind("demo", Bindable.ofInstance(demoConfigurationProperties));

    Assertions.assertEquals(Map.of("foo-*", 4, "*-foo", 5, "*-foo-*", 6), demoConfigurationProperties.getProperties());
}

Note above that all properties which are bound from environment have same value 6 but in environment only one property has value 6.

NOTE: I'm using Spring Boot 2.4.1

Regards,

Comment From: ztomic

On Spring Boot 2.2.10.RELEASE output is not same on each run. (I know it is an unsupported version, just wanted to make sure that my problem is not tied exclusively to the new version)

E.g.

org.opentest4j.AssertionFailedError: 
Expected :{*-foo-*=6, *-foo=5, foo-*=4}
Actual   :{*-foo-*=3, *-foo=2, foo-*=1, -foo-=6, foo-=6, -foo=5}
org.opentest4j.AssertionFailedError: 
Expected :{*-foo-*=6, foo-*=4, *-foo=5}
Actual   :{*-foo-*=3, foo-*=1, *-foo=2, -foo=5, foo-=5, -foo-=5}
org.opentest4j.AssertionFailedError: 
Expected :{foo-*=4, *-foo-*=6, *-foo=5}
Actual   :{foo-*=1, *-foo-*=3, *-foo=2, -foo-=6, foo-=6, -foo=5}

Comment From: wilkinsona

This is working as documented. Properties with special characters in their name must by wrapped in [].

Comment From: ztomic

Thanks, sorry for opened issue, missed that part in documentation.