You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shiro.apache.org by "Benjamin Marwell (Jira)" <ji...@apache.org> on 2020/03/28 10:23:00 UTC
[jira] [Comment Edited] (SHIRO-751) SimplePrincipalMap and
SimplePrincipalCollection throw different exceptions for the same problem
[ https://issues.apache.org/jira/browse/SHIRO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17069374#comment-17069374 ]
Benjamin Marwell edited comment on SHIRO-751 at 3/28/20, 10:22 AM:
-------------------------------------------------------------------
{quote}Can the SimplePrincipalMap be modified to throw IllegalArgumentException?
{quote}
Uhm… I'd vote for "{color:#0747a6}{{null}}{color} in, {color:#0747a6}{{NullPointerException}}{color} out". {color:#0747a6}{{IllegalArgumentException}}{color} should in my opinion be reserved for non-{color:#0747a6}{{null}}{color} arguments which have invalid content, e.g. an empty realm name.
was (Author: mampf86):
{quote}Can the SimplePrincipalMap be modified to throw IllegalArgumentException?
{quote}
Uhm… I'd vote for "{color:#0747a6}{{null}}{color} in, {color:#0747a6}{{NullPointerException}}{color} out". {color:#0747a6}{{IllegalArgumentException}}{color} should in my opinion be reserved for non-{color:#0747a6}{{null}}{color} arguments which have invalid content, e.g. an empty principal.
> SimplePrincipalMap and SimplePrincipalCollection throw different exceptions for the same problem
> ------------------------------------------------------------------------------------------------
>
> Key: SHIRO-751
> URL: https://issues.apache.org/jira/browse/SHIRO-751
> Project: Shiro
> Issue Type: Bug
> Reporter: Hao Zhong
> Priority: Major
>
> When realname is null, SimplePrincipalCollection throws IllegalArgumentException:
>
> {code:java}
> public void add(Object principal, String realmName) {
> if (realmName == null) {
> throw new IllegalArgumentException("realmName argument cannot be null.");
> }
> if (principal == null) {
> throw new IllegalArgumentException("principal argument cannot be null.");
> }
> this.cachedToString = null;
> getPrincipalsLazy(realmName).add(principal);
> }
> {code}
> For the same problem, SimplePrincipalMap throws NullPointerException:
>
> {code:java}
> public Object setRealmPrincipal(String realmName, String principalName, Object principal) {
> if (realmName == null) {
> throw new NullPointerException("realmName argument cannot be null.");
> }
> ...}
>
> {code}
> IllegalArgumentException seems to be more reasonable, and my code currently catches IllegalArgumentException for this type of the problem. Can the SimplePrincipalMap be modified to throw IllegalArgumentException?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)