Uploaded image for project: 'OpenNMS'
  1. OpenNMS
  2. NMS-10477

Use a utility function instead of Integer.getInteger

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 24.0.0
    • Component/s: None
    • Security Level: Default (Default Security Scheme)
    • Labels:
      None
    • Sprint:
      Horizon - December 5th 2018, Horizon - December 12th 2018, Horizon - December 19th 2018, Horizon - January 9th 2019, Horizon - January 23rd 2019, Horizon - January 30th 2019

      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)

        Attachments

          Activity

            People

            • Assignee:
              patrick.schweizer Patrick Schweizer
              Reporter:
              patrick.schweizer Patrick Schweizer
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: