This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 69727 - NPE from Project.fireMessageLoggedEvent when running Ivy tasks repeatedly from NB
Summary: NPE from Project.fireMessageLoggedEvent when running Ivy tasks repeatedly fro...
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Ant (show other bugs)
Version: 5.x
Hardware: PC Linux
: P3 blocker (vote)
Assignee: Jesse Glick
URL: http://jira.jayasoft.org/browse/IVY-115
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-01 22:27 UTC by vitorsouza
Modified: 2006-10-23 16:39 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vitorsouza 2005-12-01 22:27:20 UTC
(Using NetBeans 5.0 Beta 2, Ant 1.6.5, Ivy 1.2a)

Ivy (http://www.jayasoft.org/ivy/) is a free Java-based dependency manager. It
integrates with ant by copying ivy's JAR to ant's lib directory. Running ant
from console works fine, but from inside NetBeans it issues the following error:

/home/[...]/build.xml:10: The following error occurred while executing this line:
jar:file:/opt/ivy-1.2a/ivy-1.2a.jar!/fr/jayasoft/ivy/ant/antlib.xml:3: taskdef A
class needed by class fr.jayasoft.ivy.ant.IvyConfigure cannot be found:
org/apache/tools/ant/Task
BUILD FAILED (total time: 0 seconds)

Tried using an external ant 1.6.5 (installed separately from NetBeans) with no
success. Tried including Ivy's JAR to ant's Classpath in "Tools" -> "Options" ->
"Miscelaneous" -> "Ant" -> "Classpath" (Basic Options), but that didn't change
anything either. Tried removing Ivy's JAR from the lib directory while it was
configured to be in the Classpath and also didn't work. Always the same message
(as above). Both ants (NB's and external) work when used in the console and
Ivy's JAR is in their lib directory.

The message is also strange. It says that the class "org/apache/tools/ant/Task"
could not be found, but that belongs to ant, not Ivy. Tried including all JARs
inside the lib directory of ant in the Classpath (using NetBeans options) but
that didn't change the result.

Running NetBeans with superuser privileges (using sudo command) also didn't help.
Comment 1 Jesse Glick 2005-12-01 23:00:03 UTC
I need exact instructions to reproduce from scratch. I will use a fresh NB dev
build and a fresh user directory. What should I download and place where? What
script should I run?

Generally adding JARs to the Ant installation dir is discouraged. Instead, refer
to the JAR in a known location from the build script (use <taskdef/> with
classpath). However it still ought to work as on the command line if you append
the JAR to the additional classpath.

http://ant.netbeans.org/faq.html
Comment 2 vitorsouza 2005-12-02 15:43:00 UTC
DETAILED INSTRUCTIONS:

Using: Kubuntu 5.10 (Breezy), kernel 2.6.12-10-686, KDE 3.5
Sun's JDK 5 Update 6 - installed using the procedure described in
https://wiki.ubuntu.com/RestrictedFormats#head-e2ebd70ede0e3eb2117ffbd618d2295dd1540dca


I - Installation of NetBeans:

Installed sjsas_pe-8_1_02_2005Q2-nb-5_0-beta2-bin-linux.bin (NetBeans IDE 5.0
Beta 2 and Sun Java System Application Server 8.1_02) into the directory
/opt/netbeans-5.0. Using Sun's JDK Update 6.


II - Installation of External Ant:

External Ant was installed using apt-get. Package ant in Ubuntu's repositories
is version 1.6.5 (Apache Ant version 1.6.5 compiled on September 14 2005). Ant
is installed in /usr/share/ant1.6 and a symlink was placed in /usr/bin/ant.


III - Installation of Ivy:

Visited the webpage http://www.jayasoft.org/ivy/download and clicked on the link
"bin" in "The latest stable version of ivy is 1.2a: you can download bin, src
and src with deps". Unpacked the zip file in /opt, creating /opt/ivy-1.2a. Ivy's
JAR is /opt/ivy-1.2a/ivy-1.2a.jar. Created a symlink of this JAR in
/usr/share/ant1.6/lib for it to work with the external ant.


IV - Reproducing the error:

1) Run NetBeans with: netbeans -J-Dorg.apache.tools.ant.module=0

2) Created new project of type "Java Application", named IvyTest in
/home/vitor/workspace/IvyTest. Set as Main Project, do not create Main class.

3) Opened the project's build.xml, added xmlns:ivy="antlib:fr.jayasoft.ivy.ant"
to the <project> tag and the following target right below the <import
file="nbproject/build-impl.xml"/> tag:
  <target name="-post-init">
    <ivy:retrieve />
  </target>

4) Created ivy.xml file in the same directory as build.xml, with the following
contents:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="1.0">
  <info organisation="none" module="ivytest" />
  <dependencies>
    <dependency org="apache" name="commons-beanutils" rev="1.7.0" />
  </dependencies>
</ivy-module>

5) Clicked on Build Main Project (F11). It displayed a big message starting with
"Ant could not find the task or a class this task relies upon.", which is the
same that is displayed in the console if I remove the ivy JAR from the lib
directory. So far so good.

6) Opened Tools -> Options -> Miscellaneous -> Ant -> Classpath -> Manage
Classpath.... Added /opt/ivy-1.2a/ivy-1.2a.jar to it. Clicked OK.

7) Clicked on Build Main Project (F11). It displayed the following error:
/home/vitor/workspace/IvyTest/build.xml:10: java.lang.NullPointerException
BUILD FAILED (total time: 0 seconds)

8) Opened a console in the project's dir, typed "ant" and it worked normally
(using external ant).
Comment 3 vitorsouza 2005-12-02 15:52:15 UTC
Just started another project and this time NetBeans was already configured and
everything. Copied build.xml and ivy.xml from my old project and it worked! Then
I purpusefully placed a wrong parameter in one of the tags, so NetBeans issued
an error. After I corrected it, NetBeans continued to issue the error. I closed
and reopened NetBeans and it was working again.

This is weird. Please let me know if you need any other information or if you
want me to test something in particular.
Comment 4 Jesse Glick 2005-12-02 21:21:35 UTC
OK, should be enough, I'll try to reproduce shortly. Thanks!
Comment 5 Jesse Glick 2005-12-13 20:34:32 UTC
My environment:

Fedora Core 4, all updates
JDK 1.6 "Mustang" b63
NB dev 051212

- downloaded Ivy 1.2a to /tmp/ivy-1.2a

- created /tmp/test69727 j2seproject

- edited build.xml and added ivy.xml as you specify

- F11 -> expected failure (no such task)

- added ivy-1.2a.jar to Ant cp in Options

- F11 -> Output Window shows downloads, build succeeds, 5 JARs appear in Files
under /tmp/test69727/lib

So far as expected. But if I change e.g.

    <dependency org="apache" name="commons-beanutils" rev="1.7.0"/>
 
to

    <dependency org="apache" name="commons-beanutils" rev="1.7.0">

in ivy.xml and do F11, letting the build fail, and then correct it and run F11
again, sometimes I get a NPE. (Not your original taskdef failure.) Running
internal Ant in Verbose mode, I see

...
java.lang.NullPointerException
        at org.apache.tools.ant.Project.fireMessageLoggedEvent(Project.java:2006)
        at org.apache.tools.ant.Project.fireMessageLogged(Project.java:2029)
        at org.apache.tools.ant.Project.log(Project.java:357)
        at fr.jayasoft.ivy.ant.AntMessageImpl.log(AntMessageImpl.java:27)
...

Examining sources for Project reveals that the 'listeners' field is null. I'm
not sure how that could be.
Comment 6 Jesse Glick 2005-12-13 21:29:12 UTC
I know how to solve it - without knowing exactly why it happens. NB's
BridgeImpl.gutProject, which tries to prevent memory leaks from bugs in Ant core
or tasks, appears to be responsible (nulls out the field Project.listeners); can
fix it to not do so (just clear the listeners vector). The fix appears to work
and should be harmless, so I will put it in the trunk for 5.1.

The question is why gutProject matters. It is called in a separate thread; the
task is initiated after the Ant build finishes. Debugging logs do not contradict
the expected order of events: the build is started, the build terminates with an
error, the Ant module closes everything up, then gutProject runs. In other
words, the field appears to be null *before* gutProject has set it to null.

Issue #51962 had a superficially similar error, but in that case there was
actually code spawned asynch (inside other parts of NB) by the Ant process which
ran well after the Ant build was supposed to be finished. That is not the case here.

And of course if you turn on too much logging, the problem stops happening,
meaning it is sensitive to either thread behavior or garbage collector behavior.
Comment 7 Jesse Glick 2005-12-13 21:47:03 UTC
Hah, I think I found it. Bug in Ivy's Ant tasks. I will file it for them.
Comment 8 Jesse Glick 2005-12-13 22:15:47 UTC
See Ivy bug report in link. The NB patch can be considered a workaround for the
most obvious symptom but cannot fix the root problem. You might find other
anomalies when working with Ivy tasks, e.g. diagnostic output appearing in an
old output window tab rather than the one currently in use.
Comment 9 Jesse Glick 2005-12-13 22:17:12 UTC
More helpful summary.
Comment 10 Jesse Glick 2005-12-14 20:10:21 UTC
Workaround in place:

whecommitted     Up-To-Date  1.29       
ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java
Comment 11 Jesse Glick 2006-01-29 20:40:43 UTC
Bug fixed in Ivy 1.3 RC1, so please upgrade.