You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Niclas Hedhman (JIRA)" <di...@incubator.apache.org> on 2005/09/02 06:24:12 UTC

[jira] Created: (DIR-113) Usage of NullArgumentException to precondition public methods.

Usage of NullArgumentException to precondition public methods.
--------------------------------------------------------------

         Key: DIR-113
         URL: http://issues.apache.org/jira/browse/DIR-113
     Project: Directory
        Type: Improvement
 Reporter: Niclas Hedhman
 Assigned to: Alex Karasulu 
    Priority: Minor


All public methods of any subsystem should check all arguments for validity. One such check is to ensure that null is not passed when not semantically supported by the method. The exception should also be meaningful, and point stronger to the caller's fault, than a NullPointerException normally indicates.

The patch to follow makes this fairly simple.

public void doSomething( String arg1, String arg2 )
{
    NullArgumentException.validate( arg1, "arg1", 1 );
    NullArgumentException.validate( arg2, "arg2", 2 );
}

will throw an NullArgumentException (extending IllegalArgumentException) if the argument is null, with the following message;

The class org.apache.directory.SomeClass passed a null argument for the first parameter "arg1" on line 123, to the doSomething() method in class org.apache.directory.SomeOtherClass.


Furthermore, the output pattern can be modified by NullArgumentException.setPattern() which takes java.text.MessageFormat patterns.



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (DIR-113) Usage of NullArgumentException to precondition public methods.

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
     [ https://issues.apache.org/jira/browse/DIR-113?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny closed DIR-113.
---------------------------------


> Usage of NullArgumentException to precondition public methods.
> --------------------------------------------------------------
>
>                 Key: DIR-113
>                 URL: https://issues.apache.org/jira/browse/DIR-113
>             Project: Directory
>          Issue Type: Improvement
>            Reporter: Niclas Hedhman
>            Assignee: Alex Karasulu
>            Priority: Minor
>         Attachments: Main.java, Main2.java, NullArgumentException.java
>
>
> All public methods of any subsystem should check all arguments for validity. One such check is to ensure that null is not passed when not semantically supported by the method. The exception should also be meaningful, and point stronger to the caller's fault, than a NullPointerException normally indicates.
> The patch to follow makes this fairly simple.
> public void doSomething( String arg1, String arg2 )
> {
>     NullArgumentException.validate( arg1, "arg1", 1 );
>     NullArgumentException.validate( arg2, "arg2", 2 );
> }
> will throw an NullArgumentException (extending IllegalArgumentException) if the argument is null, with the following message;
> The class org.apache.directory.SomeClass passed a null argument for the first parameter "arg1" on line 123, to the doSomething() method in class org.apache.directory.SomeOtherClass.
> Furthermore, the output pattern can be modified by NullArgumentException.setPattern() which takes java.text.MessageFormat patterns.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (DIR-113) Usage of NullArgumentException to precondition public methods.

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
     [ https://issues.apache.org/jira/browse/DIR-113?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny resolved DIR-113.
-----------------------------------

    Resolution: Fixed

The best ould be to use assert instead of a specific piece of code. This is what assert are for.

> Usage of NullArgumentException to precondition public methods.
> --------------------------------------------------------------
>
>                 Key: DIR-113
>                 URL: https://issues.apache.org/jira/browse/DIR-113
>             Project: Directory
>          Issue Type: Improvement
>            Reporter: Niclas Hedhman
>         Assigned To: Alex Karasulu
>            Priority: Minor
>         Attachments: Main.java, Main2.java, NullArgumentException.java
>
>
> All public methods of any subsystem should check all arguments for validity. One such check is to ensure that null is not passed when not semantically supported by the method. The exception should also be meaningful, and point stronger to the caller's fault, than a NullPointerException normally indicates.
> The patch to follow makes this fairly simple.
> public void doSomething( String arg1, String arg2 )
> {
>     NullArgumentException.validate( arg1, "arg1", 1 );
>     NullArgumentException.validate( arg2, "arg2", 2 );
> }
> will throw an NullArgumentException (extending IllegalArgumentException) if the argument is null, with the following message;
> The class org.apache.directory.SomeClass passed a null argument for the first parameter "arg1" on line 123, to the doSomething() method in class org.apache.directory.SomeOtherClass.
> Furthermore, the output pattern can be modified by NullArgumentException.setPattern() which takes java.text.MessageFormat patterns.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DIR-113) Usage of NullArgumentException to precondition public methods.

Posted by "Niclas Hedhman (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIR-113?page=all ]

Niclas Hedhman updated DIR-113:
-------------------------------

    Attachment: Main.java

And correct file would be good...

> Usage of NullArgumentException to precondition public methods.
> --------------------------------------------------------------
>
>          Key: DIR-113
>          URL: http://issues.apache.org/jira/browse/DIR-113
>      Project: Directory
>         Type: Improvement
>     Reporter: Niclas Hedhman
>     Assignee: Alex Karasulu
>     Priority: Minor
>  Attachments: Main.java, Main2.java, NullArgumentException.java
>
> All public methods of any subsystem should check all arguments for validity. One such check is to ensure that null is not passed when not semantically supported by the method. The exception should also be meaningful, and point stronger to the caller's fault, than a NullPointerException normally indicates.
> The patch to follow makes this fairly simple.
> public void doSomething( String arg1, String arg2 )
> {
>     NullArgumentException.validate( arg1, "arg1", 1 );
>     NullArgumentException.validate( arg2, "arg2", 2 );
> }
> will throw an NullArgumentException (extending IllegalArgumentException) if the argument is null, with the following message;
> The class org.apache.directory.SomeClass passed a null argument for the first parameter "arg1" on line 123, to the doSomething() method in class org.apache.directory.SomeOtherClass.
> Furthermore, the output pattern can be modified by NullArgumentException.setPattern() which takes java.text.MessageFormat patterns.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIR-113) Usage of NullArgumentException to precondition public methods.

Posted by "Niclas Hedhman (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIR-113?page=all ]

Niclas Hedhman updated DIR-113:
-------------------------------

    Attachment: NullArgumentException.java

The NullArgumentException class.

> Usage of NullArgumentException to precondition public methods.
> --------------------------------------------------------------
>
>          Key: DIR-113
>          URL: http://issues.apache.org/jira/browse/DIR-113
>      Project: Directory
>         Type: Improvement
>     Reporter: Niclas Hedhman
>     Assignee: Alex Karasulu
>     Priority: Minor
>  Attachments: NullArgumentException.java
>
> All public methods of any subsystem should check all arguments for validity. One such check is to ensure that null is not passed when not semantically supported by the method. The exception should also be meaningful, and point stronger to the caller's fault, than a NullPointerException normally indicates.
> The patch to follow makes this fairly simple.
> public void doSomething( String arg1, String arg2 )
> {
>     NullArgumentException.validate( arg1, "arg1", 1 );
>     NullArgumentException.validate( arg2, "arg2", 2 );
> }
> will throw an NullArgumentException (extending IllegalArgumentException) if the argument is null, with the following message;
> The class org.apache.directory.SomeClass passed a null argument for the first parameter "arg1" on line 123, to the doSomething() method in class org.apache.directory.SomeOtherClass.
> Furthermore, the output pattern can be modified by NullArgumentException.setPattern() which takes java.text.MessageFormat patterns.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIR-113) Usage of NullArgumentException to precondition public methods.

Posted by "Niclas Hedhman (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIR-113?page=all ]

Niclas Hedhman updated DIR-113:
-------------------------------

    Attachment:     (was: Main.class)

> Usage of NullArgumentException to precondition public methods.
> --------------------------------------------------------------
>
>          Key: DIR-113
>          URL: http://issues.apache.org/jira/browse/DIR-113
>      Project: Directory
>         Type: Improvement
>     Reporter: Niclas Hedhman
>     Assignee: Alex Karasulu
>     Priority: Minor
>  Attachments: Main2.java, NullArgumentException.java
>
> All public methods of any subsystem should check all arguments for validity. One such check is to ensure that null is not passed when not semantically supported by the method. The exception should also be meaningful, and point stronger to the caller's fault, than a NullPointerException normally indicates.
> The patch to follow makes this fairly simple.
> public void doSomething( String arg1, String arg2 )
> {
>     NullArgumentException.validate( arg1, "arg1", 1 );
>     NullArgumentException.validate( arg2, "arg2", 2 );
> }
> will throw an NullArgumentException (extending IllegalArgumentException) if the argument is null, with the following message;
> The class org.apache.directory.SomeClass passed a null argument for the first parameter "arg1" on line 123, to the doSomething() method in class org.apache.directory.SomeOtherClass.
> Furthermore, the output pattern can be modified by NullArgumentException.setPattern() which takes java.text.MessageFormat patterns.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIR-113) Usage of NullArgumentException to precondition public methods.

Posted by "Niclas Hedhman (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIR-113?page=all ]

Niclas Hedhman updated DIR-113:
-------------------------------

    Attachment: Main2.java
                Main.class

Two simple classes that tests the NullArgumentException class. I guess should be converted to JUnit, but...

> Usage of NullArgumentException to precondition public methods.
> --------------------------------------------------------------
>
>          Key: DIR-113
>          URL: http://issues.apache.org/jira/browse/DIR-113
>      Project: Directory
>         Type: Improvement
>     Reporter: Niclas Hedhman
>     Assignee: Alex Karasulu
>     Priority: Minor
>  Attachments: Main2.java, NullArgumentException.java
>
> All public methods of any subsystem should check all arguments for validity. One such check is to ensure that null is not passed when not semantically supported by the method. The exception should also be meaningful, and point stronger to the caller's fault, than a NullPointerException normally indicates.
> The patch to follow makes this fairly simple.
> public void doSomething( String arg1, String arg2 )
> {
>     NullArgumentException.validate( arg1, "arg1", 1 );
>     NullArgumentException.validate( arg2, "arg2", 2 );
> }
> will throw an NullArgumentException (extending IllegalArgumentException) if the argument is null, with the following message;
> The class org.apache.directory.SomeClass passed a null argument for the first parameter "arg1" on line 123, to the doSomething() method in class org.apache.directory.SomeOtherClass.
> Furthermore, the output pattern can be modified by NullArgumentException.setPattern() which takes java.text.MessageFormat patterns.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira