[jcifs] no chance to run jcifs_0.7.0b7

andrea.lanza at frameweb.it andrea.lanza at frameweb.it
Mon Nov 11 22:56:04 EST 2002


It' still me....
I am not able to solve the problem

java.net.MalformedURLException: unknown protocol: smb

I got about the same problem in my developing tool (IBM Visual age for
java, Ent. Edition version 3.5.6), not only in
my testing environment (IBM WebSphere application server, version 3.5.6)

The problem is this:
If I write only one java code line program in my scrapbook:

jcifs.smb.SmbFile sourceFile = new jcifs.smb.SmbFile ("smb://");

and I use jcifs_0.7.0b3, everything is OK.

If I use jcifs_0.7.0b7 I got an error (actually VisualAge for Java opens a
debugger form).
If I look at the debugger, the last method called is
Handler.parseURL(URL,String,int,int), and is being called by
URL(URL context, String spec, URLStreamHandler handler)

It is the last line of URL(....) that is calling handler.parseURL.
Then I got a NoSuchMethodError (?!?)
Is perhaps a jdk problem ?????
Do I miss any new java classes ???
Becouse if i reach the end of the URL(...) code I should have passed the
malformed url exception....
I have this code for URL: (java.net.URL of course...)

      public URL(URL context, String spec, URLStreamHandler handler)
      throws MalformedURLException
      {
      String original = spec;
      int i, limit, c;
      int start = 0;
      String newProtocol = null;
      boolean aRef=false;

      // Check for permission to specify a handler
      if (handler != null) {
          SecurityManager sm = System.getSecurityManager();
          if (sm != null) {
            checkSpecifyHandler(sm);
          }
      }

      try {
          limit = spec.length();
          while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
            limit--;    //eliminate trailing whitespace
          }
          while ((start < limit) && (spec.charAt(start) <= ' ')) {
            start++;    // eliminate leading whitespace
          }

          if (spec.regionMatches(true, start, "url:", 0, 4)) {
            start += 4;
          }

             if (start < spec.length() && spec.charAt(start) == '#') {
            /* we're assuming this is a ref relative to the context URL.
             * This means protocols cannot start w/ '#', but we must parse
             * ref URL's like: "hello:there" w/ a ':' in them.
             */
            aRef=true;
          }
          for (i = start ; !aRef && (i < limit) &&
                 ((c = spec.charAt(i)) != '/') ; i++) {
            if (c == ':') {
                String s = spec.substring(start, i).toLowerCase();
                if (isValidProtocol(s)) {
                  newProtocol = s;
                  start = i + 1;
                }
                break;
            }
          }

          // Only use our context if the protocols match.
          if ((context != null) && ((newProtocol == null) ||
                            newProtocol.equals(context.protocol))) {
            protocol = context.protocol;
            host = context.host;
            port = context.port;
            file = context.file;
            // inherit the protocol handler as well from the context
            // if not specified to the contructor
            if (handler == null) {
                handler = context.handler;
            }
          } else {
            protocol = newProtocol;
          }

          if (protocol == null) {
            throw new MalformedURLException("no protocol: "+original);
          }

          // Get the protocol handler if not specified or the protocol
          // of the context could not be used
          if (handler == null &&
              (handler = getURLStreamHandler(protocol)) == null) {
            throw new MalformedURLException("unknown protocol: "+protocol);
          }

          this.handler = handler;

          i = spec.indexOf('#', start);
          if (i >= 0) {
            ref = spec.substring(i + 1, limit);
            limit = i;
          }
------------------>         handler.parseURL(this, spec, start, limit);

      } catch(MalformedURLException e) {
          throw e;
      } catch(Exception e) {
          throw new MalformedURLException(original + ": " + e);
      }
      }

Following the debug, I found that the handler I am using is a

jcifs.smb.Handler

then I followed debugging the source of jcifs.smb.Handler.: I reached again
the last line

 setURL( u, "smb://", u.getHost(), getDefaultPort(),
                    u.getAuthority(), u.getUserInfo(),
                    u.getPath(), u.getQuery(), u.getRef() );

So I discovered that my NoSuchMethodError depends on u.getAuthority()
method that does not exists.
But also other elements do not exist ( u.getAuthority(), u.getUserInfo(),
u.getPath(), u.getQuery()) !
Besides, setURL method is not implemented, so I think it comes from
URLStreamHandler. But the method from the lattest class accept only 6
argouments, not 9 !
I really do not undestand ( perhaps becouse my java knowledge is very low
?)


thanks in advance,

Andrea









More information about the jcifs mailing list