You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Mark D. Hansen" <m....@verizon.net> on 2005/01/04 17:19:15 UTC

org.apache.tools.ant.ProjectHelper.parse(...) throws a NullPointerException

I'm using Ant 1.6.2 and junit.  When using ProjectHelperImpl.parse(...) to parse an existing build file, an NPE is thrown at org.apache.tools.ant.types.Description.getDescription(Description.java:78).  The Description.getDescription() method is shown below and line #78 is marked.  It seems that there are no "ant.target" references defined and a null Vector gets returned.  Is this a bug or have I not initialized something properly? I have no problems running all the targets from this build file when using Ant from the command line.  This NPE only shows up when trying to use Ant inside java.

Thanks for any help you can offer!

Here is snipped of Ant source that throws the NPE (from org.apache.tools.ant.types.Description):

    public static String getDescription(Project project) {
        StringBuffer description = new StringBuffer();
        Vector targets = (Vector) project.getReference("ant.targets");
#78      for (int i = 0; i < targets.size(); i++) {
            Target t = (Target) targets.elementAt(i);
            concatDescriptions(project, t, description);
        }
        return description.toString();
    }

Here is the code fragment throwing the NPE:

    Project antProject = new Project();
    ProjectHelper helper = ProjectHelper.getProjectHelper();
    antProject.init();
    DefaultLogger logger = new DefaultLogger();
    logger.setOutputPrintStream(System.out);
    logger.setMessageOutputLevel(Project.MSG_INFO);
    antProject.addBuildListener(logger);
    String base_dir = System.getProperty("soa-book.home");
    File build_xml_chap5oneway = new File
      (base_dir + "/samples/chap5/oneway/build.xml");
    try {
      helper.parse(antProject, build_xml_chap5oneway);
    } catch (Exception e) {
      e.printStackTrace(); }

This is the stack trace:

    [junit] Running test.chap5.TestChapter
    [junit] java.lang.NullPointerException
    [junit] 	at org.apache.tools.ant.types.Description.getDescription(Description.java:78)
    [junit] 	at org.apache.tools.ant.Project.getDescription(Project.java:669)
    [junit] 	at org.apache.tools.ant.helper.ProjectHelperImpl$DescriptionHandler.characters(ProjectHelperImpl.java:647)
    [junit] 	at org.apache.xerces.parsers.AbstractSAXParser.characters(Unknown Source)
    [junit] 	at org.apache.xerces.impl.dtd.XMLDTDValidator.characters(Unknown Source)
    [junit] 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanContent(Unknown Source)
    [junit] 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    [junit] 	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    [junit] 	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    [junit] 	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    [junit] 	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    [junit] 	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    [junit] 	at org.apache.tools.ant.helper.ProjectHelperImpl.parse(ProjectHelperImpl.java:133)
    [junit] 	at test.chap5.TestChapter.testChap5oneway(TestChapter.java:52)
    [junit] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [junit] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [junit] 	at java.lang.reflect.Method.invoke(Method.java:324)
    [junit] 	at junit.framework.TestCase.runTest(TestCase.java:154)
    [junit] 	at junit.framework.TestCase.runBare(TestCase.java:127)
    [junit] 	at junit.framework.TestResult$1.protect(TestResult.java:106)
    [junit] 	at junit.framework.TestResult.runProtected(TestResult.java:124)
    [junit] 	at junit.framework.TestResult.run(TestResult.java:109)
    [junit] 	at junit.framework.TestCase.run(TestCase.java:118)
    [junit] 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    [junit] 	at junit.framework.TestSuite.run(TestSuite.java:203)
    [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
    [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:656)
    [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)

This is my build file:

<?xml version="1.0"?>
<!DOCTYPE project [
  <!ENTITY user-properties SYSTEM "file:../../../user-defined-properties.xml">
  <!ENTITY properties SYSTEM "file:../../../xmls/properties.xml"> 
  <!ENTITY paths      SYSTEM "file:../../../xmls/path_refs.xml">
  <!ENTITY tasks      SYSTEM "file:../../../xmls/taskdefs.xml">
  <!ENTITY targets    SYSTEM "file:../../../xmls/targets.xml">
  <!ENTITY sample-tasks      SYSTEM "file:../../../xmls/sample-taskdefs.xml">
  <!ENTITY sample-targets    SYSTEM "file:../../../xmls/sample-targets.xml">
]>
<project name="SimpleOneWayMessaging" default="build"
  basedir="."> 

  <description>
    See help.html (or type "ant help" if you have specified a browser in the
    user-defined-properties.xml) for a detailed message describing the project
    tasks in this section. 

    Author: Mark Hansen (m.hansen@alum.mit.edu)
    Copyright (c) 2005 Javector Software LLC
  </description>

  <!-- Sample Parameters =================================== -->
  <property name="chap" value="chap5"/>
  <property name="sec" value="oneway"/>
  <!-- web service app for deployment -->
  <property name="wsapp" value="PrintMessage"/>
  <!-- run clients with TCP monitor on or off -->
  <property name="turn-monitor-on" value="off"/>

  <!-- Include the global XML files -->
  &user-properties;
  &properties;
  &paths;
  &tasks;
  &targets;
  &sample-tasks;
  &sample-targets;

  <!-- TARGETS ============================================= -->
 
  <!-- Default deployment and implementation parameters -->
  <!-- set to: "axis" or "was" -->
  <property name="impl.jaxrpc" value="axis"/>
  <!-- set to: the URL where the service is deployed -->
  <property name="url.endpoint" value="${url.local.axis}/${wsapp}"/>
  <!-- set to: the URL where the service's WSDL is deployed -->
  <property name="url.wsdl" value="${url.local.axis}/${wsapp}?WSDL"/>
  <!-- set to: local or london -->
  <property name="deploy.location" value="local"/>

  <target name="run">
    <antcall target="run-client-template"/>
  </target>

  <target name="run-local">
    <antcall target="run-client-template">
      <param name="deploy.location" value="local"/>
    </antcall>
  </target>

  <!-- RUN-CLIENT-TEMPLATE -->
  <target name="run-client-template" depends="configure-client-log4j">
    <echo>
      Running the client against a One-Way Blocking web
      service using the ${impl.jaxrpc} JAX-RPC client implementation
      classes.
    </echo>
    <antcall target="simple-jaxrpc-client-${impl.jaxrpc}">
      <param name="wsdlURL" value="${url.wsdl}"/>
      <param name="nameSpace" value="http://jaxrpc.ws.javector.com"/>
      <param name="svcName" value="${wsapp}"/>
      <param name="svcPortName" value="${wsapp}"/>
      <param name="filePath" value="${dir.samples}/${chap}/${sec}/etc/po.xml"/>
      <param name="opType" value="oneway"/>
    </antcall>
    <echo>
      Running the client against a One-Way Non-Blocking web
      service using the ${impl.jaxrpc} JAX-RPC client implementation
      classes.
    </echo>
    <antcall target="simple-jaxrpc-client-${impl.jaxrpc}">
      <param name="wsdlURL" value="${url.wsdl}"/>
      <param name="nameSpace" value="http://jaxrpc.ws.javector.com"/>
      <param name="svcName" value="${wsapp}"/>
      <param name="svcPortName" value="${wsapp}"/>
      <param name="filePath" value="${dir.samples}/${chap}/${sec}/etc/po.xml"/>
      <param name="opType" value="oneway-nonblock"/>
    </antcall>
  </target>

  <!-- GENERATE-DEPLOYMENT-FILES -->
  <target name="generate-deployment-files">
    <delete dir="${dir.work.sec}"/>
    <mkdir dir="${dir.work.sec}"/>
    <!-- Build local WSDL from template.  Use XSLT to remove
    comments and filtering to replace tokens. -->
    <xslt
      in="${dir.src}/${path.ws}/jaxrpc/OneWayService.wsdl.template"
      out="${dir.work.sec}/tmp.wsdl" force="true"
      style="${dir.samples}/xmls/remove-comments.xsl"/>
    <copy file="${dir.work.sec}/tmp.wsdl"
      tofile="${dir.lib.sec}/${deploy.location}/${wsapp}.wsdl"
      filtering="true" overwrite="true">
      <!-- service specific paramters -->
      <filterset>
	<filter token="msgTypeNamespace" 
	  value="http://types.schema.javector.com"/>
	<filter token="msgType" value="Message"/>
	<filter token="service" value="${wsapp}"/>
	<!-- WHERE SHOULD SCHEMAS REALLY BE STORED ??? -->
	<!-- PROBABLY SHOULD RUN A HTTP REPOSITORY WITH SAMPLES ... -->
	<filter token="msgTypeSchemaLocation"
	  value="file://localhost/${dir.src}/${path.jaxrpc}/GenericMessageType.xsd"/>
	<filter token="location" value="${url.endpoint}"/>
      </filterset>
    </copy>
    <antcall target="generate-deploy-wsdd-axis">
      <param name="deployTemplate"
	value="${dir.build.deploy}/axis/oneway-deploy.wsdd"/> 
      <param name="undeployTemplate"
	value="${dir.build.deploy}/axis/oneway-undeploy.wsdd"/> 
      <param name="svcName" value="${wsapp}"/>
      <param name="endptAddr" value="${url.endpoint}"/>
      <param name="outputDir" value="${dir.lib.sec}/${deploy.location}"/>
    </antcall>
    <antcall target="generate-service-soap-skeleton-axis">
      <param name="skeletonTemplate"
	value="${dir.build.deploy}/axis/oneway-ServiceSOAPBindingSkeleton.java"/> 
      <param name="implClass" value="samples.${chap}.${sec}.${wsapp}"/>
      <param name="outputDir" value="${dir.work.sec}"/>
    </antcall>
  </target>


  <!-- COMPILE -->
  <target name="compile" depends="init, prepare">
    <!-- PrintMessage.java is compiled along with Axis WSDL2Java
    generated classes. -->
    <antcall target="compile-axis-service"/>
  </target>
 
  <!-- PACKAGE -->
  <target name="package">
    <antcall target="axis-package"/>
  </target>

  <!-- DEPLOY-SERVICE-LOCAL -->
  <target name="deploy-service-local">
    <antcall target="axis-deploy-location">
      <param name="deployTo" value="local"/>
    </antcall>
  </target>

  <!-- DEPLOY-SERVICE-LONDON -->
  <target name="deploy-service-london">
    <antcall target="axis-deploy-location">
      <param name="deployTo" value="london"/>
    </antcall>
  </target>

  <!-- UNDEPLOY-SERVICE-LOCAL -->
  <target name="undeploy-service-local">
    <antcall target="axis-undeploy-location">
      <param name="deployTo" value="local"/> 
    </antcall>
  </target>

  <!-- UNDEPLOY-SERVICE-LONDON -->
  <target name="undeploy-service-london">
    <antcall target="axis-undeploy-location">
      <param name="deployTo" value="london"/>
    </antcall>
  </target>

  <!-- Test Build Targets -->
  <target name="setprops">
    <dependset>
      <srcfileset dir="${dir.sec}"
	includes="**/*.java, **/*.properties, **/*.xml"
	excludes="**/CVS/**"/>
      <targetfileset file="${dir.lib.sec}/${wsapp}.jar"/>
    </dependset>
    <available property="donot.build.sample"
      file="${dir.lib.sec}/${wsapp}.jar"/>
    <echo message="donot.build.sample = ${donot.build.sample}"/>
  </target>

  <target name="build-all" unless="donot.build.sample">
    <echo message="building samples.${chap}.${sec}"/>
    <antcall target="clean-all"/>
    <antcall target="generate-deployment-files"/>
    <antcall target="compile"/>
    <antcall target="package"/>
  </target>

  <target name="test-all" depends="build, test"/>

  <!-- Targets Required by Testing Framework -->
  <target name="clean">
    <antcall target="clean-all"/>
  </target>

  <target name="build" depends="setprops">
    <antcall target="build-all"/>
  </target>

  <target name="test">
    <antcall target="deploy-run-local"/>
  </target>

</project>

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


Re: org.apache.tools.ant.ProjectHelper.parse(...) throws a NullPointerException

Posted by Matt Benson <gu...@yahoo.com>.
--- "Mark D. Hansen" <m....@verizon.net> wrote:

> I'm using Ant 1.6.2 and junit.  When using
> ProjectHelperImpl.parse(...) to parse an existing
> build file, an NPE is thrown at
> 
[SNIP]

It looks like a (not "the") cause for your problem is
your use of ProjectHelperImpl.  Do you have this
explicitly set in the
org.apache.tools.ant.ProjectHelper property? 
Otherwise I am at a loss as to why you are seeing this
class in use at all.  Ordinarily later versions of Ant
will default to using ProjectHelper2.  While it does
appear the Description possibly should not be throwing
that NPE, using ProjectHelper2 might make it a
non-issue for you.

-Matt


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

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