Bug 459188 - InternalAntRunner tries to set null user property
Summary: InternalAntRunner tries to set null user property
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 4.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.5 M6   Edit
Assignee: Rob Stryker CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2015-02-05 01:43 EST by Rob Stryker CLA
Modified: 2015-03-16 07:06 EDT (History)
2 users (show)

See Also:


Attachments
Do not set user properties if value is null (2.42 KB, patch)
2015-02-05 01:43 EST, Rob Stryker CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Stryker CLA 2015-02-05 01:43:20 EST
Created attachment 250516 [details]
Do not set user properties if value is null

Related bug:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=338633

Here is a new stacktrace for Mars:

java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:459)
	at org.apache.tools.ant.PropertyHelper.setUserProperty(PropertyHelper.java:750)
	at org.apache.tools.ant.Project.setUserProperty(Project.java:563)
	at org.eclipse.ant.internal.core.ant.InternalAntRunner.setProperties(InternalAntRunner.java:267)
	at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:632)
	at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:525)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.eclipse.ant.core.AntRunner.run(AntRunner.java:371)
	at org.eclipse.pde.internal.core.exports.FeatureExportOperation.runScript(FeatureExportOperation.java:423)
	at org.eclipse.pde.internal.core.exports.FeatureExportOperation.doExport(FeatureExportOperation.java:261)
	at org.eclipse.pde.internal.core.exports.FeatureBasedExportOperation.run(FeatureBasedExportOperation.java:50)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)



Looking at the code here:  http://git.eclipse.org/c/platform/eclipse.platform.git/tree/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java#n1035

We can see that the variable userProperties is a HashMap, which permits the use of a null value. This means the method setProperties() which has the following code may be passing in a null value:

	private void setProperties(Project project) {
		setBuiltInProperties(project);
		if (userProperties != null) {
			for (Entry<String, String> entry : userProperties.entrySet()) {
				project.setUserProperty(entry.getKey(), entry.getValue());
			}
		}
	}

Following the stack, however, wee see that the internal implementation for project.setUserProperty(k,v) leads to PropertyHelper, which uses a HashTable as an internal implementation, which does not allow null values. 

InternalAntRunner should make sure there are no null values being passed in here!

A similar problem is shown in the other InternalAntRunner:   http://git.eclipse.org/c/platform/eclipse.platform.git/tree/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java#n268

No null checks are performed.
Comment 1 Michael Rennie CLA 2015-02-05 10:05:24 EST
Pushed patch to master:

http://git.eclipse.org/c/platform/eclipse.platform.git/commit/?id=608b1481160755e3e8dacceca5f7a1782195f6cc

As it turns out we have (potentially) been violating the Ant API for a while around setting user props - the methods are all spec'd to not accept null. 

Thanks for the patch Rob!
Comment 2 Sarika Sinha CLA 2015-03-16 07:06:35 EDT
Verified by code inspect and PDE case scenario.
Eclipse SDK

Version: Mars (4.5)
Build id: I20150315-2000