Skip to content

Properties getting trimmed since 2.0 #13602

Closed

Description

@jacekkruger

The following application running under Spring Boot 1.5.14 outputs

	:1
abc   :6

but after upgrading to 2.0.0 outputs

:0
abc:3

Is that intended behavior? The comment on #4106 by @wilkinsona suggests that properties should not be trimmed. But discussion under #11029 suggests that there were in fact some changes related to trimming of collection properties.

I used a "separator" property in an application that does CSV parsing just like in the example below. The separator is a tab and with 2.0 it seems I have no way to specify that via properties.

Application.java:

@SpringBootApplication
@ConfigurationProperties("application")
public class Application {

    private String separator;

    private String string;

    public String getSeparator() {
        return separator;
    }

    public void setSeparator(String separator) {
        this.separator = separator;
    }

    public String getString() {
        return string;
    }

    public void setString(String string) {
        this.string = string;
    }

    @PostConstruct
    void postConstruct() {
        System.out.println(separator + ":" + separator.length());
        System.out.println(string + ":" + string.length());
    }

    public static void main(String args[]) {
        SpringApplication.run(Application.class, args);
    }

}

application.properties:

application.separator=\t
application.string=   abc   

Activity

  1. added
    status: waiting-for-triage
    on Jun 27, 2018
  2. added
    for: team-attention
    on Jun 28, 2018
  3. philwebb commented on Jun 30, 2018

    @philwebb
    Member

    This discussion in #11029 specifically relates to binding comma-separated strings to collections and arrays. E.g. you can have properties some.value=Fred, Velma,Daphne bound to List<String> and it will contain ["Fred", "Velma", "Daphne"]. That change was driven mainly by the StringToCollectionConverter in Spring Framework which trims elements.

    I think the trimming of other values is more problematic unless we can provide a sensible way to escape things. From a quick glance, it's not entirely clear which part of the Spring Boot code is actually trimming those values. Nothing in org.springframework.boot.context.properties.bind seems to be doing it. Perhaps it's related to our new property loading. We'll need to dig a bit deeper.

  4. philwebb commented on Jun 30, 2018

    @philwebb
    Member

    This is a bug in OriginTrackedPropertiesLoader. If I add "withspace= with " to the test-properties.properties used by OriginTrackedPropertiesLoaderTests then compareToJavaProperties fails.

  5. added
    type: bug
    and removed
    for: team-attention
    status: waiting-for-triage
    on Jun 30, 2018
  6. added this to the 2.0.x milestone on Jun 30, 2018
  7. self-assigned this
    on Jul 2, 2018
  8. modified the milestones: 2.0.x, 2.0.4 on Jul 2, 2018
  9. jacekkruger commented on Jul 3, 2018

    @jacekkruger
    Author

    It should work just like before now but I'm also curious why is the leading whitespace trimmed? Haven't found that documented anywhere.

  10. wilkinsona commented on Jul 3, 2018

    @wilkinsona
    Member

    It's specified in the javadoc for Properties.load where it says:

    Any white space after the key is skipped; if the first non-white space character after the key is '=' or ':', then it is ignored and any white space characters after it are also skipped. All remaining characters on the line become part of the associated element string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions