You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2006/02/12 04:23:29 UTC

DO NOT REPLY [Bug 38622] New: - NullPointerException raised if deprecated ProjectHelper.configureProject is not called

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38622>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38622

           Summary: NullPointerException raised if deprecated
                    ProjectHelper.configureProject is not called
           Product: Ant
           Version: 1.6.5
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core
        AssignedTo: dev@ant.apache.org
        ReportedBy: eross@m-qube.com


ImportTask raises NPE unless static configureProject is called

e.g.

    [junit] java.lang.NullPointerException
    [junit]     at
org.apache.tools.ant.taskdefs.ImportTask.execute(ImportTask.java:96)
    [junit]     at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    [junit]     at org.apache.tools.ant.Task.perform(Task.java:364)
    [junit]     at org.apache.tools.ant.Target.execute(Target.java:341)
    [junit]     at
org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:142)
    [junit]     at AntUtil.createProject(AntUtil.java:67)

Example client class:

  public static Project createProject(File buildFile, Properties prop) throws
BuildException {
    sLog.debug("createProject file=" + buildFile + " prop=" + prop);
    Project project = new Project();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    project.setCoreLoader(cl);
    project.fireBuildStarted();
    project.init();
    ProjectHelper ph = ProjectHelper.getProjectHelper();
    // ProjectHelper.configureProject is deprecated but if <import/>
    // is used generates NullPointerException ... d'oh
    ph.configureProject(project, buildFile);
    ph.parse(project, buildFile);
    for (Iterator i = prop.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry me = (Map.Entry)i.next();
      project.setUserProperty((String)me.getKey(), (String)me.getValue());
    }
    return project;
  }

Problem code:

src/main/org/apache/tools/ant/taskdefs/ImportTask.java

    public void execute() {
        if (file == null) {
            throw new BuildException("import requires file attribute");
        }
        if (getOwningTarget() == null
            || !"".equals(getOwningTarget().getName())) {
            throw new BuildException("import only allowed as a top-level task");
        }

        ProjectHelper helper =
                (ProjectHelper) getProject().getReference("ant.projectHelper");

^^^^^^^^^^ helper is null unless ProjectHelper.configureProject is called

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38622] - NullPointerException raised if deprecated ProjectHelper.configureProject is not called

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38622>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38622


jkf@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED




------- Additional Comments From jkf@apache.org  2006-02-13 20:33 -------
Just that the deprecated flag is gone.

The described problem will not occur anymore, and would not have occured when
using ant without providing your own entry point / project.

If you want to report another issue / improvement, you are of course welcome to
do so, but in that case please use a new bug report / enhancement request.

By the way, 

ProjectHelper ph = ProjectHelper.getProjectHelper();
    // ProjectHelper.configureProject is deprecated but if <import/>
    // is used generates NullPointerException ... d'oh
    ph.configureProject(project, buildFile);
    ph.parse(project, buildFile);

can be replaced by 

ProjectHelper.configureProject(project, buildFile);

It implies as far as I rememer the ProjectHelper.getProjectHelper() and
ph.parse(project, buildFile) call.

Before using that projecthelper one can retrieve that same projectHelper from
the project by doing
ProjectHelper helper =
                (ProjectHelper) getProject().
                    getReference(ProjectHelper.PROJECTHELPER_REFERENCE);




-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38622] - NullPointerException raised if deprecated ProjectHelper.configureProject is not called

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38622>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38622


jkf@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Additional Comments From jkf@apache.org  2006-02-12 13:35 -------
ProjectHelper.configureProject is not deprecated anymore in the ANT 1.7 line.

Added a check

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 38622] - NullPointerException raised if deprecated ProjectHelper.configureProject is not called

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38622>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38622


eross@m-qube.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




------- Additional Comments From eross@m-qube.com  2006-02-12 22:05 -------

It would be nice not to have to do both calls:

    ph.configureProject(project, buildFile);
    ph.parse(project, buildFile);

Are you saying that the ImportTask no longer depends on the "configureProject"
call?  Or, just that the deprecated flag is gone?

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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