[ 
https://issues.apache.org/jira/browse/FELIX-6742?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17902393#comment-17902393
 ] 

Konrad Windszus edited comment on FELIX-6742 at 12/2/24 6:55 PM:
-----------------------------------------------------------------

The coercion rules are defined by 
https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.component.html#service.component-component.property.value.coercion
 and prescribe using {{Long.parseNumber(String)}} for conversion from String to 
Long. This is IMHO rather an issue with the internal felix persistence handler 
for the Config Admin 
(https://github.com/apache/felix-dev/blob/master/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java)
 or the way you pass the config dictionary object to the Configuration Admin 
API than with Felix SCR.


was (Author: kwin):
The coercion rules are defined by 
https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.component.html#service.component-component.property.value.coercion
 and prescribe using {{Long.parseNumber(String)}} for conversion from String to 
Long. This is IMHO rather an issue with the internal felix persistence handler 
for the Config Admin 
(https://github.com/apache/felix-dev/blob/master/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java)
 than with Felix SCR.

> 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
>            Priority: Major
>
> 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