Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326679

Summary: [regression] NPE running Ant task
Product: [Eclipse Project] PDE Reporter: Michael Rennie <Michael_Rennie>
Component: API ToolsAssignee: Curtis Windatt <curtis.windatt.public>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: darin.eclipse
Version: 3.6   
Target Milestone: 3.7 M3   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Possible Fix none

Description Michael Rennie CLA 2010-09-30 10:57:04 EDT
3.7M2a

Running a custom Ant task that creates an API baseline and tries to add components to it no longer works in 3.7M2a with the following NPE reported:


batchmigration] scan:
[batchmigration] 
[batchmigration] java.lang.NullPointerException
[batchmigration] /home/apiadmin/tasks/buildfiles/migrationscan.xml:19: java.lang.NullPointerException
[batchmigration] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
[batchmigration] 	at org.apache.tools.ant.Task.perform(Task.java:348)
[batchmigration] 	at org.apache.tools.ant.Target.execute(Target.java:357)
[batchmigration] 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
[batchmigration] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[batchmigration] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[batchmigration] 	at com.ibm.api.scans.servertools.tasks.ServerTask.runSubProject(ServerTask.java:158)
[batchmigration] 	at com.ibm.api.scans.servertools.tasks.BatchMigration.checkProduct(BatchMigration.java:184)
[batchmigration] 	at com.ibm.api.scans.servertools.tasks.BatchMigration.execute(BatchMigration.java:149)
[batchmigration] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[batchmigration] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[batchmigration] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
[batchmigration] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[batchmigration] 	at java.lang.reflect.Method.invoke(Method.java:618)
[batchmigration] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[batchmigration] 	at org.apache.tools.ant.Task.perform(Task.java:348)
[batchmigration] 	at org.apache.tools.ant.Target.execute(Target.java:357)
[batchmigration] 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
[batchmigration] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[batchmigration] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[batchmigration] 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[batchmigration] 	at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[batchmigration] 	at org.apache.tools.ant.Main.runBuild(Main.java:758)
[batchmigration] 	at org.apache.tools.ant.Main.startAnt(Main.java:217)
[batchmigration] 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[batchmigration] 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[batchmigration] Caused by: java.lang.NullPointerException
[batchmigration] 	at org.eclipse.pde.api.tools.internal.model.ApiModelFactory.addComponents(ApiModelFactory.java:209)
[batchmigration] 	at org.eclipse.pde.api.tools.internal.tasks.CommonUtilsTask.createBaseline(CommonUtilsTask.java:74)
[batchmigration] 	at org.eclipse.pde.api.tools.internal.tasks.ApiMigrationTask.getBaseline(ApiMigrationTask.java:306)
[batchmigration] 	at org.eclipse.pde.api.tools.internal.tasks.ApiMigrationTask.execute(ApiMigrationTask.java:222)
[batchmigration] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[batchmigration] 	at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
[batchmigration] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[batchmigration] 	at java.lang.reflect.Method.invoke(Method.java:618)
[batchmigration] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[batchmigration] 	... 25 more
[batchmigration] --- Nested Exception ---
[batchmigration] java.lang.NullPointerException
[batchmigration] 	at org.eclipse.pde.api.tools.internal.model.ApiModelFactory.addComponents(ApiModelFactory.java:209)
[batchmigration] 	at org.eclipse.pde.api.tools.internal.tasks.CommonUtilsTask.createBaseline(CommonUtilsTask.java:74)
[batchmigration] 	at org.eclipse.pde.api.tools.internal.tasks.ApiMigrationTask.getBaseline(ApiMigrationTask.java:306)
[batchmigration] 	at org.eclipse.pde.api.tools.internal.tasks.ApiMigrationTask.execute(ApiMigrationTask.java:222)
[batchmigration] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[batchmigration] 	at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
[batchmigration] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[batchmigration] 	at java.lang.reflect.Method.invoke(Method.java:618)
[batchmigration] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[batchmigration] 	at org.apache.tools.ant.Task.perform(Task.java:348)
[batchmigration] 	at org.apache.tools.ant.Target.execute(Target.java:357)
[batchmigration] 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
[batchmigration] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[batchmigration] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[batchmigration] 	at com.ibm.api.scans.servertools.tasks.ServerTask.runSubProject(ServerTask.java:158)
[batchmigration] 	at com.ibm.api.scans.servertools.tasks.BatchMigration.checkProduct(BatchMigration.java:184)
[batchmigration] 	at com.ibm.api.scans.servertools.tasks.BatchMigration.execute(BatchMigration.java:149)
[batchmigration] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[batchmigration] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[batchmigration] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
[batchmigration] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[batchmigration] 	at java.lang.reflect.Method.invoke(Method.java:618)
[batchmigration] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[batchmigration] 	at org.apache.tools.ant.Task.perform(Task.java:348)
[batchmigration] 	at org.apache.tools.ant.Target.execute(Target.java:357)
[batchmigration] 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
[batchmigration] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[batchmigration] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[batchmigration] 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[batchmigration] 	at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[batchmigration] 	at org.apache.tools.ant.Main.runBuild(Main.java:758)
[batchmigration] 	at org.apache.tools.ant.Main.startAnt(Main.java:217)
[batchmigration] 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[batchmigration] 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Looks like the fix to bug 322572 is the culprit here, as the bundle might not have been started - no instance of ApiPlugin has been created.

Steps:
1. create ant Ant task that creates an API baseline
2. add the api.tools bundle on the Ant classpath
3. run the task

Happens:

NPE

Expected:

works as it always has
Comment 1 Michael Rennie CLA 2010-10-20 11:48:48 EDT
It would make sense that if there is no bundle context (it hasn't been started) the method should fall back to its old behavior.
Comment 2 Curtis Windatt CLA 2010-10-20 12:03:48 EDT
Created attachment 181307 [details]
Possible Fix

If we don't have a bundle context, can we still call code from PDE at all?  If so, this patch will fix the problem by using PDE code directly rather than accessing it through the service (if there is no bundle context available).

If we cannot call any code from PDE, then we'll have to put back in the original code that scanned a directory.  However, this will cause behaviour to differ significantly between having/not having a context.
Comment 3 Darin Wright CLA 2010-10-20 15:09:33 EDT
Applied/Fixed.
Comment 4 Michael Rennie CLA 2010-11-01 15:10:06 EDT
verified