Sai Zhang created DERBY-6695:
--------------------------------

             Summary: Improving configuration code: should not silently replace 
an invalid value with the default one
                 Key: DERBY-6695
                 URL: https://issues.apache.org/jira/browse/DERBY-6695
             Project: Derby
          Issue Type: Bug
    Affects Versions: 10.10.1.1
         Environment: All envrionments
            Reporter: Sai Zhang


Dear Derby developers,

I have been using Derby for a while, and think the configuration handling code 
should be improved. In particular, Derby should check the validity of a 
user-specified configuration value, rather than replacing an invalid value with 
the default.

Not sure that is a major issue or not. But at least it happens to me a couple 
of times, and causes lots of confusion. Thus, I strongly suggest to fix this.

How to reproduce the problem.

set:

derby.storage.pageSize= l2800 ( note the first char is "l" (L), not "1")

clearly, this invalid value should be notified immediately (or at least 
logged), however, Derby simply replaces that with the default value, which 
seems to be "32768".  This is a real example, and causes confusion.

I looked at the code and found the improving code:

In class PropertyUtil

public static int handleInt(String value, int min, int max, int defaultValue) {

                if (value == null)
                        return defaultValue;

                try {
                        int intValue = Integer.parseInt(value);
                        if ((intValue >= min) && (intValue <= max))
                                return intValue;
                }
                catch (NumberFormatException nfe)
                {
                        // just leave the default.
                }
                return defaultValue;
        }

I would suggest to add logging statements for the invalid cases, and produce an 
error message to indicate which configuration value is incorrect.

I have a few more such cases, if you are interested in improving the code, I am 
happy to share that too.

Please let me know your thought.

-Sai




--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to