Skip to content

Space characters in bsh.classpath.BshClassPath.getRTJarPath() #24

@peetscott

Description

@peetscott

This is probably a Windows specific issue.

Suppose java is located here

C:\Program Files\Java\jre1.8.0_91

getRTJarPath() returns this String:

/C:/Program%20Files/Java/jre1.8.0_91/lib/rt.jar

getBootClassPath() uses the String to create a URL from
a File (line 659). But

  1. new File("/C:/Program%20Files/Java/jre1.8.0_91/lib/rt.jar")
    is not a valid File.
  2. new File("/C:/Program%20Files/Java/jre1.8.0_91/lib/rt.jar").toURI()
    produces
    file:/C:/Program%2520Files/Java/jre1.8.0_91/lib/rt.jar
    which is a corrupt URI. toURI() wants to encode the '%' character
    without realizing that the space character has already been
    encoded. To be expected because File does not recognize encoded
    characters.

toURL() propagates the error.

searchJarForClasses() tries to URL.openStream() and it fails.

Try this:

cp = this.namespace.getClassManager().getClassPath();
cp.getClassSource("java.lang.Object");

It returns null.


Possible Solutions

(1.) Do

urlString.replaceAll("%20", " ");

before returning from getRTJarPath(). This handles encoded space characters in
the path. There could still be other encoded characters though.

(2.) Create the URL directly from getRTJarPath().

public static BshClassPath getBootClassPath() 
  throws ClassPathException  {
     ...
  URL url = new URL("file:" + getRTJarPath());
     ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions