Use a utility function instead of Integer.getInteger

Description

In order to get a System Property we use throughout opennms Integer.getInteger() instead of System.getProperty(). This saves us the conversion from a String to an int and thus makes the code more readable and simpler.
However we loose the ability to detect wrong / unusable values (a String that can't be converted to a number).
Integer.getInteger() just returns the default value. It would be desirable to log a wrong value and thus allow to find configuration problems easier.

Idea:

  • write a helper function to provide the same functionality as Integer.getInteger() but log invalid values

  • replace all Integer.getInteger calls

  • add a checkstyle check to prevent further usage of Integer.getInteger

The concept can of course not only be applied to Integer.getInteger but also to other value types such as primitives like Long.getLong() or Enums.

Also System.getProperty itself could be a candidate if we want to apply a restriction to the String value, like: String getString(String propertyName, String defaultValue, String regex)

Acceptance / Success Criteria

None

Lucidchart Diagrams

Activity

Show:

Jesse White January 23, 2019 at 3:06 PM

Patrick Schweizer November 30, 2018 at 12:52 PM

Fixed

Details

Assignee

Reporter

Sprint

Fix versions

Priority

PagerDuty

Created November 27, 2018 at 11:28 PM
Updated January 25, 2019 at 1:57 PM
Resolved January 25, 2019 at 1:57 PM

Flag notifications