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

Bug 325664

Summary: [localdiscovery] StringIndexOutOfBoundsException when Remote-Service path is at root of bundle
Product: [RT] ECF Reporter: Neil Bartlett <njbartlett>
Component: ecf.remoteservicesAssignee: Scott Lewis <slewis>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: slewis
Version: 3.3.0   
Target Milestone: 3.4.0   
Hardware: All   
OS: All   
Whiteboard:

Description Neil Bartlett CLA 2010-09-17 18:55:38 EDT
An exception is thrown if the path indicated in Remote-Service does not include at least one '/' character (i.e. is at the root of the bundle). For example:

   Remote-Service: my-service.xml

will throw the following exception:

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1937)
	at org.eclipse.ecf.osgi.services.discovery.local.BundleTrackerImpl.handleRemoteService(BundleTrackerImpl.java:180)
	at org.eclipse.ecf.osgi.services.discovery.local.BundleTrackerImpl.getRemoteServiceInformationFilesFromBundle(BundleTrackerImpl.java:157)
	at org.eclipse.ecf.osgi.services.discovery.local.BundleTrackerImpl.checkBundleAndPublishServices(BundleTrackerImpl.java:88)
	at org.eclipse.ecf.osgi.services.discovery.local.BundleTrackerImpl.addingBundle(BundleTrackerImpl.java:78)
Comment 1 Scott Lewis CLA 2010-09-17 21:48:16 EDT
Fix released to HEAD.

Fix was to replace this code:

		String path = token.substring(0, token.lastIndexOf("/"));

with this

		int lastSlash = token.lastIndexOf("/");
		String path = (lastSlash <= 0)?"/":token.substring(0,lastSlash);

This assures that if the there is no slash at all, or the slash is in the first position, the intention is to assume the file is at the bundle root ("/")

Resolving as fixed.  Thanks Neil for the report.