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 2013/01/09 08:58:14 UTC

[jira] [Closed] (OFBIZ-4989) printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception

     [ https://issues.apache.org/jira/browse/OFBIZ-4989?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacques Le Roux closed OFBIZ-4989.
----------------------------------

    Resolution: Duplicate

Duplicate of OFBIZ-4987
                
> printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception
> -----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-4989
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4989
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Christoph Neuroth
>
> This code in GenericEntity.java:
> {code}
>             Debug.logWarning("The field name (or key) [" + name + "] is not valid for entity [" + this.getEntityName() + "], printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception.", module);
> {code}
> is really annoying and IMHO it is really wrong. First, it does not print an exception, it only prints that string with no stacktrace (I think that was changed at some point). Second, IllegalArgument is a RuntimeException so the interface does not need to allow it to be thrown.
> Personally, I think the warning is not even neccessary. We often don't know exactly what kind of model we're dealing with and just check if it has that field or not. With this code, to prevent excessive log clutter, we have to wrap each call with a "containsKey". A java map will just return null silently as well.
> If anyone is really worried about accessing fields wrong (your tests should catch that error), there could be an extra method "getOrThrow" or something, but get should just return the value or null.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira