The generation of this article is a summary of a bug, is a bottom-up record, not intended to have a global understanding, later have the opportunity to systematic analysis. Git address: github.com/fw103699437…

Bug show

Application. Yml content

num: 0010
Copy the code

code

    @Autowired
    Environment environment;
    @Login
    @RequestMapping("/method")
    public Entity method(@LoginUser Entity entity, @RequestBody Entity entity1){
        System.out.println(environment.getProperty("num"));
        return entity;
    }
Copy the code

The results of

8
Copy the code

You can see that the properties in the environment are inconsistent with the properties in the yML configuration file. The configuration file in the project is not 10, so you can easily guess that 0010 is octal when reading

bug trace

Few words said, directly above, if is not clear, you can click the link www.processon.com/view/link/5…

The process is as follows: 1: container start 2: trigger listener 3: response listener read configuration 4: Parse YML using SNaKEYAML 5: parse MAP key-value pairs 6: parse map value (now there is a problem)

The offending code is as follows

public class ConstructYamlInt extends AbstractConstruct {
        @Override
        public Object construct(Node node) {
            String value = constructScalar((ScalarNode) node).toString().replaceAll("_"."");
            int sign = +1;
            char first = value.charAt(0);
            if (first == The '-') {
                sign = -1;
                value = value.substring(1);
            } else if (first == '+') {
                value = value.substring(1);
            }
            int base = 10;
            if ("0".equals(value)) {
                return Integer.valueOf(0);
            } else if (value.startsWith("0b")) {
                value = value.substring(2);
                base = 2;
            } else if (value.startsWith("0x")) {
                value = value.substring(2);
                base = 16;
                // Since we are 0010, we enter here, base
            } else if (value.startsWith("0")) {
                value = value.substring(1);
                base = 8;
            } else if (value.indexOf(':') != -1) {
                String[] digits = value.split(":");
                int bes = 1;
                int val = 0;
                for (int i = 0, j = digits.length; i < j; i++) {
                    val += Long.parseLong(digits[j - i - 1]) * bes;
                    bes *= 60;
                }
                return createNumber(sign, String.valueOf(val), 10);
            } else {
                return createNumber(sign, value, 10);
            }
            returncreateNumber(sign, value, base); }}Copy the code

To solve

Now that you can see where the problem is, all you need to do is make the value not start with 0 and enclose it in double quotes. (Or not yML? Hahaha)

After double quotation marks

0010
Copy the code

After changing to Properties

0010
Copy the code

idea

After can fix the spring surveillance mechanism and load file (including system properties, the bootstrap/application, the difference between the properties/yml)