Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-214

Adding an integer and getting it as a long causes an exception

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: 1.3
    • Component/s: None
    • Labels:
      None
    • Environment:

      Linux, java 1.5

      Description

      Try this in a BeanShell:

      bsh % p = new org.apache.commons.configuration.PropertiesConfiguration();
      bsh % p.setProperty("foo", 6);
      bsh % p.getLong("foo");
      // Error: // Uncaught Exception: Method Invocation p.getLong : at Line: 3 : in file: <unknown file> : p .getLong ( "foo" )

      Target exception: org.apache.commons.configuration.ConversionException: 'foo' doesn't map to a Long object

      org.apache.commons.configuration.ConversionException: 'foo' doesn't map to a Long object
      at org.apache.commons.configuration.AbstractConfiguration.getLong(AbstractConfiguration.java:667)

      The problem is that when an object in a property is not a Long, the only attempt of PropertyConverter.toLong() is that of treating it as a string. It could try to convert it to a Number first and then try to convert it to a long. It is a very confusing behaviour, because if you save and reload the properties everything works fine (as now the integer is a string).

        Attachments

          Activity

            People

            • Assignee:
              oheger Oliver Heger
              Reporter:
              vigna Sebastiano Vigna
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: