Link to home
Start Free TrialLog in
Avatar of wex
wex

asked on

Making an URLConnection

I don't understand why the call to getResponseCode() below gives an UnsatisfiedLinkError.

          URL url = new URL(docName);
          HttpURLConnection checkURL =  (HttpURLConnection)url.openConnection();
          try {
            if (checkURL.getResponseCode() == 404)
            {
              System.err.println("Failed to get doc " + docName);
              return;
            }
          } catch (UnsatisfiedLinkError ule) {
            System.err.println("Unable to resolve docname " + docName);
            return;
          } catch (NullPointerException npe) {
            System.err.println("Can't get doc " + docName);
            return;
          }

If I understand the docs correctly, openConnection() should call connect() for me.
The other weird thing is that this code ran fine under 1.1.2, but fails under 1.1.3 and later.
Avatar of msmolyak
msmolyak

Is it possible that you have multiple JDK  installations on your machine with environment variables pointing to the more than one at a time. For example your CLASSPATH may point to JDK1.1.2\lib\classes.zip while your PATH may contain JDK1.1.3\bin directory. That may cause the described behaviour. (The DLL on your path does not contain the exact native function the JVM is trying to invoke).
Avatar of wex

ASKER

Yeah, I think that's the right track, but I'm confused why it's happening.  I'm on a UNIX box
and the only relevant thing on my PATH is /usr/java/bin

My CLASSPATH includes only the directories relevant to my project; I'm depending on
java to add the proper directories for its own .class files.  Is that an error?
It's hard for me to speak about UNIX since I do my development on NT. Each JDK come with set of class files and set of executables and dynamic libraries (shared objects in UNIX). When I install subsequent versions of JDK I install them in different directories which causes my to update CLASSPATH and PATH each time I do that. What you are saying is that your path keeps pointing to /usr/java/bin. Does it mean that each new installation overwrites an older one? Is it the only possible way to install JDK?

Anyway, why don't you find out for sure where the classes.zip and the executables (such as java) for the version you want to use are. You can do it by using "which java" command and renaming directories where class libraries are.

Not putting classes.zip on a classpath is not an error as long as you know that it uses the right version. In your case you don't seem to be sure of that.
Avatar of wex

ASKER

There's no classes.zip file in there.  I've checked for it.
I've also checked for the possibility of multiple installations and there's only one on each machine.
The executables are clearly in /usr/java/bin
I checked that and it's the standard approach where everything points to one java_wrapper script which (among a zillion other things) sets the CLASSPATH.

What baffles me is why there's only one file which it can't find.  When I get the stack trace from this error, it looks like this:
java.lang.UnsatisfiedLinkError: getInetFamily
        at java.net.InetAddress.<init>(InetAddress.java:63)
        at
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:201)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:219)
        at sun.net.www.http.HttpClient.New(HttpClient.java:230)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:326)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:407)
        at Footprints.database.convert.ReadPath.parse(ReadPath.java:329)
        at Footprints.database.convert.ReadPath.main(ReadPath.java:896)

So it only fails on finding something in java.net.InetFamily (InetAddress).  If the other .class files are found, why not this particular one?

I'm still baffled.
What OS are you using?
Avatar of wex

ASKER

I'm using IRIX 6.1 as it happens, but you were essentially correct.
It's a CLASSPATH problem.  I can't figure out how to go back and give you the points.
I guess if you post a new answer I can accept it and you'll get the points that way?
ASKER CERTIFIED SOLUTION
Avatar of msmolyak
msmolyak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wex

ASKER

OK, the problem was indeed with my $CLASSPATH
36 hours of wild-goose chasing later I've finally gotten it working.