[jira] [Commented] (OFBIZ-11281) Possible Nullpointer in StringUtil#strToMap

2019-12-01 Thread Mathieu Lirzin (Jira)


[ 
https://issues.apache.org/jira/browse/OFBIZ-11281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16985636#comment-16985636
 ] 

Mathieu Lirzin commented on OFBIZ-11281:


[~uHeidfeld] Thanks for your answer, Indeed for dates there is no notion of 
emptiness like in collections, the Optional class can model the emptiness 
for such kind of types in a type safe manner. IMO there is no need to worry 
about allocating empty collections (The JVM is very powerful and such 
allocation is most case negligeable).

After some investigation it appears that strToMap is only used in the framework 
in 
/ofbiz/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/valuelink/ValueLinkApi.java
 for doing ad-hoc parsing (meaning not good ;-)) that will eventually be 
reimplemented which would lead to strToMap deprecation/removal, as a 
consequence  I think you should consider using your own implementation of map 
parsing to replace strToMap in your code.

[~nmalin] As I understand it, {{StringUtil}} is mostly legacy stuff that will 
be deprecated/removed sooner or later so I am not sure adding more flexibility 
is desirable in this context, it would be better to work on getting rid of 
remaining legacy code and in the case of ‘strToXXX‘ use standard serialisation 
formats like JSON, XML, CSV or other alternatives but backed with a serious 
parser. :-)

> Possible Nullpointer in StringUtil#strToMap
> ---
>
> Key: OFBIZ-11281
> URL: https://issues.apache.org/jira/browse/OFBIZ-11281
> Project: OFBiz
>  Issue Type: Bug
>Affects Versions: Trunk
>Reporter: Ulrich Heidfeld
>Assignee: Nicolas Malin
>Priority: Critical
> Fix For: 17.12.01, Upcoming Branch, 18.12.01
>
> Attachments: 
> OFBIZ-11281_Possible_Nullpointer_in_StringUtil#strToMap.patch
>
>
> StringUtil#strToMap(String, String, boolean, String) throws Nullpointer for 
> StringUtil.strToMap("", false).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (OFBIZ-11281) Possible Nullpointer in StringUtil#strToMap

2019-11-22 Thread Nicolas Malin (Jira)


[ 
https://issues.apache.org/jira/browse/OFBIZ-11281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16980146#comment-16980146
 ] 

Nicolas Malin commented on OFBIZ-11281:
---

Thanks Mathieu for this return,

I analyzed a little more in depth different method of StringUtil dans I think 
we can refactorize for more coherence because functions toSet and toList throw 
an exception when it's impossible to generate the related Object or strToMap 
return null.

To offer more flexibility and coherence, I'd be tempted to reformate like that :
 * toSet, toList and toMap (will rename strToMap) will throw an exception if it 
can parse the String
 * safeToSet, safeToList and safeToMap (or other idea on name) will return null 
or empty object (we can adding a boolean in parameter to select) if the parse 
failed

> Possible Nullpointer in StringUtil#strToMap
> ---
>
> Key: OFBIZ-11281
> URL: https://issues.apache.org/jira/browse/OFBIZ-11281
> Project: OFBiz
>  Issue Type: Bug
>Affects Versions: Trunk
>Reporter: Ulrich Heidfeld
>Assignee: Nicolas Malin
>Priority: Critical
> Fix For: 17.12.01, Upcoming Branch, 18.12.01
>
> Attachments: 
> OFBIZ-11281_Possible_Nullpointer_in_StringUtil#strToMap.patch
>
>
> StringUtil#strToMap(String, String, boolean, String) throws Nullpointer for 
> StringUtil.strToMap("", false).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (OFBIZ-11281) Possible Nullpointer in StringUtil#strToMap

2019-11-15 Thread Ulrich Heidfeld (Jira)


[ 
https://issues.apache.org/jira/browse/OFBIZ-11281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16974979#comment-16974979
 ] 

Ulrich Heidfeld commented on OFBIZ-11281:
-

Hello [~mthl],
 thanks for your teaching words. 
In our project, we are using something like:
 StringUtil.strToMap(UtilProperties.getPropertyValue(...))
If there is no according property value, an empty string will be returned.

I would prefer null instead of Collections.emptyMap as return value because we 
don't need to initiate a map if it has no informations in it. In addition, if a 
date time isn't set in properties, an empty value could be take as wrong date.

> Possible Nullpointer in StringUtil#strToMap
> ---
>
> Key: OFBIZ-11281
> URL: https://issues.apache.org/jira/browse/OFBIZ-11281
> Project: OFBiz
>  Issue Type: Bug
>Affects Versions: Trunk
>Reporter: Ulrich Heidfeld
>Assignee: Nicolas Malin
>Priority: Critical
> Fix For: 17.12.01, Upcoming Branch, 18.12.01
>
> Attachments: 
> OFBIZ-11281_Possible_Nullpointer_in_StringUtil#strToMap.patch
>
>
> StringUtil#strToMap(String, String, boolean, String) throws Nullpointer for 
> StringUtil.strToMap("", false).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (OFBIZ-11281) Possible Nullpointer in StringUtil#strToMap

2019-11-14 Thread Mathieu Lirzin (Jira)


[ 
https://issues.apache.org/jira/browse/OFBIZ-11281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16974144#comment-16974144
 ] 

Mathieu Lirzin commented on OFBIZ-11281:


Hello,

First thanks providing a test case.

I think there is a confusion because "possible NPE" is not a bug per say, but 
"having an NPE at runtime" is.

To explain the important distinction let me give you an example more 
meaningful. Imagine some method signature {{Double divide(int x, int y)}}  
which calculates the result of x/y. Should we consider "Possible 
{{DivisionByZero}} exception" is a bug ?  *No*. Additionally Would it makes 
sense to return {{null}} when y = 0 ? *Probably not*.
 
So in general to fix a "NPE happening at runtime" bug, this can be done by 
either by:
- specifying that the method *must not* be called with certain values that are 
outside its domain ({{null}}, "" or whatever) and fix the caller.
- specifying explicitly that {{null}} value is part of the domain of the method 
and adapt the implementation accordingly

Regarding  [^OFBIZ-11281_Possible_Nullpointer_in_StringUtil#strToMap.patch] I 
would like to know why it would be desirable to consider the empty string part 
of the domain of {{strToMap}} and if there is a reason why {{null}} is returned 
instead of {{Collections.emptyMap}}?

> Possible Nullpointer in StringUtil#strToMap
> ---
>
> Key: OFBIZ-11281
> URL: https://issues.apache.org/jira/browse/OFBIZ-11281
> Project: OFBiz
>  Issue Type: Bug
>Affects Versions: Trunk
>Reporter: Ulrich Heidfeld
>Assignee: Nicolas Malin
>Priority: Critical
> Fix For: 17.12.01, Upcoming Branch, 18.12.01
>
> Attachments: 
> OFBIZ-11281_Possible_Nullpointer_in_StringUtil#strToMap.patch
>
>
> StringUtil#strToMap(String, String, boolean, String) throws Nullpointer for 
> StringUtil.strToMap("", false).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (OFBIZ-11281) Possible Nullpointer in StringUtil#strToMap

2019-11-13 Thread Ulrich Heidfeld (Jira)


[ 
https://issues.apache.org/jira/browse/OFBIZ-11281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16973484#comment-16973484
 ] 

Ulrich Heidfeld commented on OFBIZ-11281:
-

I have fixed this issue and added a corresponding test case in 
StringUtilTests#testStrToMap.  

> Possible Nullpointer in StringUtil#strToMap
> ---
>
> Key: OFBIZ-11281
> URL: https://issues.apache.org/jira/browse/OFBIZ-11281
> Project: OFBiz
>  Issue Type: Bug
>Affects Versions: Trunk
>Reporter: Ulrich Heidfeld
>Assignee: Ulrich Heidfeld
>Priority: Critical
> Attachments: 
> OFBIZ-11281_Possible_Nullpointer_in_StringUtil#strToMap.patch
>
>
> StringUtil#strToMap(String, String, boolean, String) throws Nullpointer for 
> StringUtil.strToMap("", false).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)