[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[Subclipse-dev] synchronization problems with SVNClientManager

From: Del Myers <delmyers.cs_at_gmail.com>
Date: 2006-09-25 21:43:53 CEST

I'm trying to write a background process in Eclipse that gathers information
from subversion, using the Subclipse plugin. Things seem to be working great for
the most part, but I think that I've found a bug that brings up an intermittent
null pointer exception. I've traced it, I think, to a problem in SVNClientManager.

The problem starts here: I'm running a background job at startup which tries to
get a SVN remote resource from an ISVNLocalResource. This propagates through the
subclipse code, until a point where a client has to be created in
SVNClientManager. At the same time, the regular subclipse code is starting up,
and it does some of the same processing.

The problem comes, I think, when both threads try to initialize the
svnClientInterface. They both see it as null, so they both call
SVNClientManager.setSvnClientInterface(null). Which looks like this:

    public void setSvnClientInterface(String svnClientInterface) {
         if (svnClientInterface == null) {
           // if no specific interface is specified, load JavaHL
           // if JavaHL fails to load, then JavaSVN will load
             loadJavaHLAdapter();
             try {
                 this.svnClientInterface =
SVNClientAdapterFactory.getPreferredSVNClientType();
             } catch (SVNClientException e) {
                 SVNProviderPlugin.log(new TeamException(new
Status(IStatus.ERROR, SVNProviderPlugin.ID, IStatus.OK, e
                         .getMessage(), e)));
                 return;
             }
         } else {
                if
(CmdLineClientAdapterFactory.COMMANDLINE_CLIENT.equals(svnClientInterface))
                 svnClientInterface = JavaSvnClientAdapterFactory.JAVASVN_CLIENT;
                if (JhlClientAdapterFactory.JAVAHL_CLIENT.equals(svnClientInterface))
                    loadJavaHLAdapter();
                if (JavaSvnClientAdapterFactory.JAVASVN_CLIENT.equals(svnClientInterface))
                    loadJavaSVNAdapter();
                if (SVNClientAdapterFactory.isSVNClientAvailable(svnClientInterface)) {
                    this.svnClientInterface = svnClientInterface;
                } else {
                    if (this.svnClientInterface == null &&
SVNClientAdapterFactory.isSVNClientAvailable(JavaSvnClientAdapterFactory.JAVASVN_CLIENT))
                        this.svnClientInterface =
JavaSvnClientAdapterFactory.JAVASVN_CLIENT;
                }
         }

At the top of the method, both threads try to call loadJavaHLAdapter(), which
looks like this:

private void loadJavaHLAdapter() {
         if (!javahl) {
             javahl = true;
                    try {
                    JhlClientAdapterFactory.setup();
                } catch (SVNClientException e) {
                    loadJavaSVNAdapter(); // try to make sure there is at least one
adapter available
                }
         }
        }

Now, the problem occurs, I think, when one thread gets through the initial "if"
statement first, and sets javahl to "true". Then the other thread comes through,
sees that javahl is true, and doesn't attempt to setup the
JhlClientAdapterFactory. The result is that svnClientInterface remains null in
setSvnClientInterface for the second thread (which happens to be my thread in
most cases). In the end, this means that a client can't be created, and I end up
with a null pointer exception.

I've been looking through the subclipse code, and it seems that there is very
little synchronization throughout the plugin. It doesn't seem to be thread-safe.
Am I missing something? Is there some kind of global thread that we can run our
jobs in in order to make sure that they are thread safe? Thanks.

Del.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subclipse.tigris.org
For additional commands, e-mail: dev-help@subclipse.tigris.org
Received on Mon Sep 25 21:44:22 2006

This is an archived mail posted to the Subclipse Dev mailing list.