JDK-6370159 : (enum) Create an enum for standard System property keys.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2006-01-09
  • Updated: 2017-05-04
  • Resolved: 2017-05-04
Related Reports
Relates :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
Could get an enum for the standard System property keys?

JUSTIFICATION :
This would reduce programming errors.

It is also quite cumbersome to write test cases that actually cover the possibility that the desired property name key has been misspelled in the code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
public final class System {

    public static String getProperty(final Property property) {
        return getProperty(property.getPropertyKey());
    }


    public enum Property {

        LINE_SEPARATOR() {
            public String getPropertyKey() {
                return "line.separator";
            }
        };


        /** Returns the key's String value. */
        public abstract String getPropertyKey();

        /** Get the system property -- delegates to System.getProperty. */
        public String getPropertyValue() {
            return getProperty(this);
        }

    }

}

ACTUAL -
Problematic String literal property keys.

---------- BEGIN SOURCE ----------
...
if (myVariable.equals(System.getProperty("1ine.separator")))
        ...
else ...
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Define your own such enum.

Comments
Most common information from system properties (version, line separator, file separator, path separator) are now available via APIs. Other information from system properties is still available, albeit via property names, which are strings. The number of remaining properties is fairly small, and none have been added for many years, so adding an enum or a set of string constants as symbolic names for these strings doesn't seem to add much value. Closing as Won't Fix.
04-05-2017