JDK-4641504 : REGRESSION: Space disallowed in URL passed to Naming.lookup()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.rmi
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-02-22
  • Updated: 2013-10-25
Related Reports
Relates :  
Description
Name: gm110360			Date: 02/21/2002


FULL PRODUCT VERSION :
java full version "1.4.0-b92"

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
Service Pack 2


A DESCRIPTION OF THE PROBLEM :
The path component of a URL can contain spaces, but in the
URL string passed to Naming.lookup(), JDK 1.4 does not
allow this.  For example, a call to Naming.lookup() with
the String "rmi://localhost:12345/test test2" fails.  It
never failed in JDK 1.3 and earlier.

This is a real problem, since I've got RMI servers in the
field based on JDK 1.1.8, 1.2, and 1.3 that contain spaces
in their registered object's names.



REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the test code provided.
2. Run it.
3. See the MalformedURLException

EXPECTED VERSUS ACTUAL BEHAVIOR :
I expect the URL provided in the test code to be a legal,
valid URL.  The program will ultimately fail with a
ConnectException, since this is only a test with no actual
remote object.  However, the program should not fail with a
MalformedURLException, since the URL provided is fine.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.net.MalformedURLException: invalid URL string:
rmi://localhost:34571/test test2
        at java.rmi.Naming.parseURL(Naming.java:266)
        at java.rmi.Naming.lookup(Naming.java:78)
        at test.main(test.java:9)
Caused by: java.net.URISyntaxException: Illegal character in path at index 26:
rmi://localhost:34571/test test2
        at java.net.URI$Parser.fail(URI.java:2701)
        at java.net.URI$Parser.checkChars(URI.java:2872)
        at java.net.URI$Parser.parseHierarchical(URI.java:2956)
        at java.net.URI$Parser.parse(URI.java:2904)
        at java.net.URI.<init>(URI.java:565)
        at java.rmi.Naming.parseURL(Naming.java:217)
        ... 2 more


This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.*;
import java.rmi.*;

public class test
{
   public static void main(String[] args) throws Exception
   {
      URL myURL = new URL("http://localhost:34571/test test2"); //works
      Naming.lookup("rmi://localhost:34571/test test2"); //fails
   }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
None found.

Release Regression From : 1.3.1_02
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 139713) 
======================================================================

Comments
EVALUATION This bug is a result of the change in the implementation of the java.rmi.Naming class to use 1.4's new java.net.URI class for parsing its URL-formatted strings, instead of using java.net.URL for this parsing (which had been the source of problems in the past). Unfortunately, java.net.URL tolerated unescaped spaces in the path component of complete URL strings (which are illegal according to RFC 2396), but java.net.URI enforces RFC 2396 much more closely, which is why the exception is getting thrown for the Naming URL that contains spaces in the name component using 1.4. The spec for java.rmi.Naming is not clear about what characters are allowed in the components of its "URL-formatted" strings, including how strictly they align with RFC 2396. In the past, the implementation has disallowed illegal characters such as '#' from the name component (because of #'s significance in indicating URI fragments), but it has tolerated illegal spaces. So applications that use embedded spaces in Naming URLs that worked with previous JDK and J2SE will fail as described with the current 1.4.0 implementation... ###@###.### 2002-02-22 There are two solutions: 1) tolerate spaces 2) clarify spec. We need to decide which is better. ###@###.### 2002-04-25
22-02-2002

WORK AROUND I can think of two possible workarounds offhand: 1. When it is desired to include a space character within the "name" component of the URL-formatted string passed to the java.rmi.Naming APIs, escape the space character as "%20" in accordance with RFC 2396 and the java.net.URI API. 2. Avoid using the java.rmi.Naming API (which is just a wrapper on top of other public APIs-- it is never neceessary to use Naming) altogether and instead directly use the LocateRegistry.getRegistry method to fabricate a registry stub and the Registry interface methods to communicate with the RMI registry represented by the registry stub. ###@###.### 2002-02-22
22-02-2002