Joerg Hoh created FELIX-6742:
--------------------------------

             Summary: SCR should parse longs from exponential notation
                 Key: FELIX-6742
                 URL: https://issues.apache.org/jira/browse/FELIX-6742
             Project: Felix
          Issue Type: Improvement
          Components: Declarative Services (SCR)
    Affects Versions: scr-2.2.12
            Reporter: Joerg Hoh



We use a SCR annotations like this for a configuration:
{noformat} 
@AttributeDefinition(...)
Long aLongProperty() default = 50000;
{noformat}

We want to overwrite this value with the value 12_000_000, and through some 
automation it ends up as string "1.2+e7" in exponential notation in the config.

Now when SCR parses this config, it fails like this:

{noformat}
The activate method has thrown an exception (org.apache.felix.log.LogException: 
org.osgi.service.component.ComponentException: java.lang.NumberFormatException: 
For input string: "1.2e+07")
org.apache.felix.log.LogException: 
org.osgi.service.component.ComponentException: java.lang.NumberFormatException: 
For input string: "1.2e+07"
        at 
org.apache.felix.scr.impl.inject.internal.Annotations$Handler.invoke(Annotations.java:379)
 [org.apache.felix.scr:2.2.12]
        at my.own.$Proxy193.aLongProperty(Unknown Source) [mybundle]
        at my.own.component.activate(component.java:229) [mybundle]
{noformat}

I found that the coercion from String to Long just uses {{Long.parseLong 
(String)}}, which cannot handle this scientific notation.

I think that it would make sense to add a fallback level and use BigDecimal to 
parse this notation and return a Long.



 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to