Bug 23095 - [ExternalTools] NullPointerException when running a target named using a space
Summary: [ExternalTools] NullPointerException when running a target named using a space
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 2.0.1   Edit
Hardware: PC Windows 2000
: P1 normal (vote)
Target Milestone: ---   Edit
Assignee: Simon Arsenault CLA
QA Contact:
URL:
Whiteboard:
Keywords: ui
Depends on:
Blocks:
 
Reported: 2002-09-03 03:35 EDT by Philippe Krief CLA
Modified: 2002-09-18 13:58 EDT (History)
3 users (show)

See Also:


Attachments
stack trace (1.69 KB, text/plain)
2002-09-03 09:32 EDT, DJ Houghton CLA
no flags Details
stack trace (with line numbers) (1.17 KB, text/plain)
2002-09-03 12:56 EDT, DJ Houghton CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Krief CLA 2002-09-03 03:35:41 EDT
Build 2.0.1
When I try to run an ANT target which contains a space in its name I get a NPE!
Test case:
================
<?xml version="1.0" ?>
<project name="ANT Tests" default="" basedir = ".">

<target name = "Test.One">
	<echo message = "'Test.One' is running!"/>
</target>
<target name = "Test Two">
	<echo message = "'Test Two' is running!"/>
</target>
</project>
================
The 2 targets I recognizes by the UI but when I try to run "Test Two" I got the 
NPE.
Thanks
Philippe
Comment 1 DJ Houghton CLA 2002-09-03 09:32:21 EDT
Created attachment 1921 [details]
stack trace
Comment 2 DJ Houghton CLA 2002-09-03 12:56:48 EDT
Created attachment 1922 [details]
stack trace (with line numbers)
Comment 3 DJ Houghton CLA 2002-09-09 15:02:56 EDT
Note that this problem did not occur in 2.0.
Comment 4 DJ Houghton CLA 2002-09-09 16:17:57 EDT
Note this works ok in the 2.1 stream builds.
Am in the process of verifying changes.
Comment 5 DJ Houghton CLA 2002-09-09 18:00:41 EDT
org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.getAntTargets()

This method returns an empty String array when it should have a single item 
which is the name of the target. (with the space in it) Debugging the code, it 
looks like #argStringToArrayList(String) is creating a StringTokenizer on 
spaces and quotes on the following string arg "${ant_target:Test Two}". 

Moving to Platform/UI [ExternalTools] for further investigation.

Created bug 23350 for putting NPE protection code around the area which failed 
in org.eclipse.ant.core.
Comment 6 Simon Arsenault CLA 2002-09-10 16:03:18 EDT
The problem is the code to split the argument string into individual argument 
items did not handle the case of variables whose content contain spaces. It 
should treat variables as one unit not try to process any space or double quote 
it may contain.

For the 2.0.1 stream, the method DefaultRunnerContext.argStringToArrayList 
should now be the following code:
	/**
	 * Parses the given string into an ArrayList of arguments.
	 * 
	 * @return the ArrayList of arguments
	 */
	private ArrayList argStringToArrayList(String s) {
		ArrayList list = new ArrayList(10);
		if (s == null)
			return list;
		
		boolean inQuotes = false;
		boolean inVar = false;
		int start = 0;
		int end = s.length();
		StringBuffer arg = new StringBuffer(end);
		
		while (start < end) {
			char ch = s.charAt(start);
			start++;
			
			switch (ch) {
				case ' ' :	//$NON-NLS-1$
					if (inQuotes || inVar) {
						arg.append(ch);
					} else {
						if (arg.length() > 0) {
							list.add(arg.toString
());
							arg.setLength(0);
						}
					}
					break;

				case '"' :	//$NON-NLS-1$
					if (inVar) {
						arg.append(ch);
					} else {
						if (start < end) {
							if (s.charAt(start) 
== '"') { //$NON-NLS-1$
								// Two quotes 
together represents one quote
								arg.append(ch);
								start++;
							} else {
								inQuotes = !
inQuotes;
							}
						} else {
							// A lone quote at the 
end, just drop it.
							inQuotes = false;
						}
					}
					break;
					
				case '$' :	//$NON-NLS-1$
					arg.append(ch);
					if (!inVar && start < end) {
						if (s.charAt(start) == '{') { //
$NON-NLS-1$
							arg.append('{'); //$NON-
NLS-1$
							inVar = true;
							start++;
						}
					}
					break;

				case '}' :	//$NON-NLS-1$
					arg.append(ch);
					inVar = false;
					break;

				default :
					arg.append(ch);
					break;
			}
			
		}
		
		if (arg.length() > 0)
			list.add(arg.toString());
			
		return list;
	}
Comment 7 Simon Arsenault CLA 2002-09-17 11:55:11 EDT
Released in the R2_0_1 stream and ported to the 2.1 stream also.