ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: New Ant Task; Null Pointer Exception
Date Tue, 11 May 2004 12:01:37 GMT
The task works for me.
However, it does not have error checking,
so if version is not set, a null pointer exception will
be thrown.

The execute method should be:

  public void execute()
  {
    if (myVersion == null) {
        throw new BuildException("Missing required attribute 'version'");
    } 
    int dot = myVersion.lastIndexOf(".");
    String buildnum = myVersion.substring(dot+1);
    getProject().setProperty("buildnum", buildnum);
  }
}

Also as Jan saids,
you should remove the "main" method as it will not work.

Also ..
the task sets the buildnum property even if it is already set.
This goes against normal ant style.
Peter

rhonda.brown@lynx.co.uk wrote:

>Hi
>   
>
>I have written a small Ant Task to amend the format of the version number so that it will
use the last 4 digits after the last period to tag the source files.
>   
>
>Example:
>   
>
>tag `Ver_release_1.0.5121_resources_120'
>   
>
>When I call the task in my build file I get this error message:
>   
>
>java.lang.NullPointerException
>        at anttask.JustBuild.execute(JustBuild.java:23)
>        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
>        at org.apache.tools.ant.Task.perform(Task.java:341)
>        at org.apache.tools.ant.Target.execute(Target.java:309)
>        at org.apache.tools.ant.Target.performTasks(Target.java:336)
>        at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
>        at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
>        at org.apache.tools.ant.Main.runBuild(Main.java:609)
>        at org.apache.tools.ant.Main.start(Main.java:196)
>        at org.apache.tools.ant.Main.main(Main.java:235)
>   
>
>This is the code that I am using:
>   
>
>package anttask;
>import org.apache.tools.ant.Task;
>import org.apache.tools.ant.Project;
>   
>
>public class JustBuild extends Task
>   
>
>{
>  public static void main(String[] args)
>  {
>    JustBuild justBuild = new JustBuild();
>    justBuild.setVersion("01.05.2004");
>    justBuild.execute();
>  }
>  private String myVersion;
> 
>
>  public void setVersion(String version)
>  {
>    myVersion = version;
>  }
> 
>
>  public void execute()
>  {
>    int dot = myVersion.lastIndexOf(".");
>    String buildnum = myVersion.substring(dot+1);
>    getProject().setProperty("buildnum", buildnum);
>    //System.out.println("this is a test");
>  }
>}
>   
>
>Project has got a Null value, but I can”t see why.
>   
>
>Can anyone see where I have gone wrong?
>   
>
>Thanks for your answers.
>   
>
>Rhonda
>   
>
>   
>
>   
>
>
>
>This message is intended only for the use of the person(s) ("The intended
>Recipient(s)") to whom it is addressed.  It may contain information which
>is privileged and confidential within the meaning of applicable law.  If
>you are not the intended recipient, please contact the sender as soon as
>possible.  The views expressed in this communication are not necessarily
>those held by LYNX Express Limited.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message