[jbosstools-dev] Error in org.jboss.tools.ws.core.test

Snjezana Peco snjezana.peco at redhat.com
Tue Oct 21 17:27:11 EDT 2008


The error happens in the 
org.jboss.tools.ws.core.classpath.JBossWSRuntimeClassPathInitializer$JBossWSRuntimeClasspathContainer.removeEntry 
method :

public void removeEntry(String jarName) {
    if (entries == null) {
        return;
    }
    IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1];
    int i = 0;
    for (IClasspathEntry entry : entries) {
        if (!entry.toString().contains(jarName)) {
            newEntries[i++] = entry;
        }
    }
    entries = newEntries;
}

The method will throw AIOOB exception if an entry named jarName doesn't 
exist.
There is yet another issue in this method. If, for instance, a classpath 
contains the following entries:
...
a.jar
aa.jar
aba.jar
...
and a client calls removeEntry("a.jar"), the method will remove all the 
above mentioned entries.
A solution for this issue would be the following :

public void removeEntry(String jarName) {
    if (entries == null) {
        return;
    }
    List<IClasspathEntry> entriesList = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry entry : entries) {
        if (entry != null) {
            IPath path = entry.getPath();
            if (path != null) {
                if (path != null && path.lastSegment() != null && 
path.lastSegment().equals(jarName)) {
                    continue;
                }
            }
            entriesList.add(entry);
        }
    }
    entries = entriesList.toArray(new IClasspathEntry[0]);
}

There is a similar issue in the 
org.jboss.tools.esb.core.runtime.JBossRuntimeClassPathInitializer.JBossRuntimeClasspathContainer.removeEntry 
method

Snjeza



More information about the jbosstools-dev mailing list