You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Jacques Le Roux (JIRA)" <ji...@apache.org> on 2011/09/17 10:38:08 UTC

[jira] [Created] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
----------------------------------------------------------------------------------------------------

                 Key: OFBIZ-4427
                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
             Project: OFBiz
          Issue Type: Improvement
          Components: framework
    Affects Versions: SVN trunk
            Reporter: Jacques Le Roux
            Priority: Minor
             Fix For: SVN trunk


Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  

Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13190805#comment-13190805 ] 

Jacques Le Roux commented on OFBIZ-4427:
----------------------------------------

Hi Paul,

Coincidentally, I was working on the style of last OFBIZ-4580 patch. I wanted to fix/improve the way the error is returned/logged when GenericEntityException is catched there. For that I wanted to use something like
{code}
String errMsg = UtilProperties.getMessage("CommonUiLabels", "CommonDatabaseProblem", messageMap, (Locale) context.get("locale"));
{code}

I found 2 issues I'm working on:
# CommonDatabaseProblem does not receive an errMessage parameter thought it's used as is OOTB, which is unrelated to our issue
# Looking into <<public static String getMessage(String resource, String name, Object[] arguments, Locale locale)>> I wanted to use UtilValidate.isEmpty(arguments) in/instead of <<if (arguments != null && arguments.length > 0) {>> and then remembered your proposition. I think it's a good idea, and would appreciate a patch

Thanks for your help
                
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Paul Foxworthy (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13183064#comment-13183064 ] 

Paul Foxworthy commented on OFBIZ-4427:
---------------------------------------

I've been doing some more thinking about this. I think UtilValidate.isEmpty() should work with an array, as Jacques said. Currently it doesn't.

There is at least one spot where isEmpty is being used with an array: https://fisheye6.atlassian.com/browse/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java?hb=true#to1441

That is very misleading code. Anyone reading it would be entitled to assume isEmpty would test for null and for an empty array.

If we do want to support arrays, and we want to remove UtilValidate.isEmpty for any Object in general, then we need to add eight overloaded versions of UtilValidate.isEmpty for arrays of each of the primitive types, plus one more for Object[].

Is that OK in order to achieve the goal of this Jira, or should we give up on compile time checking of calls to isEmpty?

                
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Paul Foxworthy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13107352#comment-13107352 ] 

Paul Foxworthy commented on OFBIZ-4427:
---------------------------------------

I like the principle, but the current implementation specifically refuses to even log a warning for commonly used classes like Number and DateTime. A comment says this is to avoid "flooding" the log. See https://fisheye6.atlassian.com/browse/~br=trunk/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java?r=1076384#to774 . For other classes the logging severity level was reduced from warning to verbose, presumably again because of the volume of log entries.
Could someone get a number on how many places are affected before we decide how to proceed?

> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13144638#comment-13144638 ] 

Jacques Le Roux commented on OFBIZ-4427:
----------------------------------------

It does not solve anything but I found interesting sizeIsEmpty in commons-collections CollectionUtils.java: www.jarvana.com/jarvana/view/commons-collections/commons-collections/3.2/commons-collections-3.2-sources.jar!/org/apache/commons/collections/CollectionUtils.java?format=ok
                
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Jacques Le Roux (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacques Le Roux reassigned OFBIZ-4427:
--------------------------------------

    Assignee: Jacques Le Roux
    
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Assignee: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch, OFBIZ-4427_isEmpty.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Adrian Crum (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13107416#comment-13107416 ] 

Adrian Crum commented on OFBIZ-4427:
------------------------------------

According to Eclipse:

166 references in Java code
25 references in scripts (bsh, groovy, xml)


> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Paul Foxworthy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13107806#comment-13107806 ] 

Paul Foxworthy commented on OFBIZ-4427:
---------------------------------------

https://fisheye6.atlassian.com/browse/~br=trunk/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java?r=1170525#to614 has a call to UtilValidate.isEmpty with appDefaultLocale, which was declared as Object. Can it be tightened to String? The call at https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java?r=1044931#to111 passes a String.

And thanks, Adrian. At a guess most of the 166 calls will be OK so there are a manageable number to fix.

> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Paul Foxworthy (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13196908#comment-13196908 ] 

Paul Foxworthy commented on OFBIZ-4427:
---------------------------------------

I have decided to only write isEmpty(Object[]) and isNotEmpty(Object[]) for the moment.

If anyone ever wants to use these methods with an array of one of the primitive types, that would not compile. We would need to add two more methods each with a parameter of the primitive array type. I think we're better off doing that when it's needed, rather than writing a complete set of sixteen methods, most of which will never be used.
                
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch, OFBIZ-4427_isEmpty.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13146831#comment-13146831 ] 

Jacques Le Roux commented on OFBIZ-4427:
----------------------------------------

Yes, I think we could add also the array type we don't have. I was hoping to find some inspiration there or even a replacement but I must say it's similar than ours
                
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Paul Foxworthy (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13146797#comment-13146797 ] 

Paul Foxworthy commented on OFBIZ-4427:
---------------------------------------

Hi Jacques,

In what way interesting? It seems similar to ObjectType.isEmpty (https://fisheye6.atlassian.com/browse/~br=trunk/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java?r=1076384#to765) and the various overloaded UtilValidate.isEmpty methods.

Cheers

Paul Foxworthy
                
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Paul Foxworthy (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Foxworthy updated OFBIZ-4427:
----------------------------------

    Attachment: OFBIZ-4427.patch

I tried commenting out isEmpty( Object ) and isNotEmpty(Object), and here's a patch for the first few problems I found. Plenty more to be done!

> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (OFBIZ-4427) Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation

Posted by "Paul Foxworthy (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Foxworthy updated OFBIZ-4427:
----------------------------------

    Attachment: OFBIZ-4427_isEmpty.patch

Here's a new patch.
I have:
- deprecated UtilValidate.isEmpty(Object) and UtilValidate.isNotEmpty(Object)
- added overloaded variants of these two methods with an Object[] parameter
- Removed isEmpty(String) and isNotEmpty(String), because String derives from CharSequence, and there is already a CharSequence overload for these methods
- detected and fixed many calls to isEmpty and isNotEmpty when all that was needed was a comparison with null

There are still many calls remaining, but they will set off a deprecation warning, so if several of us work at resolving those we can eventually eliminate the methods
                
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4427
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4427
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Jacques Le Roux
>            Priority: Minor
>              Labels: UtilValidate.isEmpty
>             Fix For: SVN trunk
>
>         Attachments: OFBIZ-4427.patch, OFBIZ-4427_isEmpty.patch
>
>
> Hence we need tp remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.  
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira