JDK-6506304 : java.net.MalformedURLException: unknown protocol: c
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-12-19
  • Updated: 2012-06-08
  • Resolved: 2009-03-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
1.4.0 1.4Fixed 6u13-revFixed 7Fixed
Description
FULL PRODUCT VERSION :
c:\>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Windows XP SP2

A DESCRIPTION OF THE PROBLEM :
When trying to parse an XML file, a java.net.MalformedURLException is thrown if there is a space anywhere within the full path file name.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a folder on the hard drive named "space error" ( note the space in the name ) and put a valid xml file in the folder.  run the program.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Exception
ACTUAL -
Exception

ERROR MESSAGES/STACK TRACES THAT OCCUR :
unknown protocol: c
java.net.MalformedURLException: unknown protocol: c
	at java.net.URL.<init>(URL.java:574)
	at java.net.URL.<init>(URL.java:464)
	at java.net.URL.<init>(URL.java:413)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
	at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1132)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:533)
	at test.main(test.java:16)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.intellij.rt.execution.application.AppMain.main(Unknown Source)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import org.xml.sax.XMLReader;
import javax.xml.parsers.*;
public class test
{
    public static void main(String[] arfgs)
    {
        try
        {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            SAXParser jaxpParser = factory.newSAXParser();
            XMLReader reader = jaxpParser.getXMLReader();
            reader.parse("C:/space error/x.xml");
            System.exit(0);
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
            e.printStackTrace();
            System.exit(16);
        }
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
use prior version or include a J2EE jar file in your class path.

Comments
SUGGESTED FIX SAP sent us a letter where they designated contributed patch as an "Error Correction" under the terms of the SCSL and contribute it for putback and integration into the Sun Java SE code base.
06-03-2009

EVALUATION Fixed in jaxp 1.4 on java.net. Will request for integration into jdk6 update release.
05-03-2009

EVALUATION There are many interests in this issue. I'm rasing the priority and asking for an integration.
02-03-2009

EVALUATION Reassign the issue to me. This is a regression from jdk1.5 as the suggested workaround and several user inputs indicated.
03-09-2008

SUGGESTED FIX This is a suggested fix, contributed by a Java Licensee - SAP. SAP would like Sun's opinion on the fix and also for us to consider including it in the SUN JDK? -- Fix suggestion -- We prepared a fix for this problem for the SAP JVM 6. It simply re-adds a small code block in com.sun.org.apache.xerces.internal.impl.XMLEntityManager.fixURI(String) that was present in JDK5, but removed in JDK6. This code replaces spaces in file names by "%20". With this change, parsing files with blanks in path names works again as expected. protected static String fixURI(String str) { // handle platform dependent strings str = str.replace(java.io.File.separatorChar, '/'); // Windows fix if (str.length() >= 2) { char ch1 = str.charAt(1); // change "C:blah" to "/C:blah" if (ch1 == ':') { char ch0 = Character.toUpperCase(str.charAt(0)); if (ch0 >= 'A' && ch0 <= 'Z') { str = "/" + str; } } // change "//blah" to "file://blah" else if (ch1 == '/' && str.charAt(0) == '/') { str = "file:" + str; } } ===== begin insert ===== // replace spaces in file names with %20. // Original comment from JDK5: the following algorithm might not be // very performant, but people who want to use invalid URI's have to // pay the price. int pos = str.indexOf(' '); if (pos >= 0) { StringBuilder sb = new StringBuilder(str.length()); // put characters before ' ' into the string builder for (int i = 0; i < pos; i++) sb.append(str.charAt(i)); // and %20 for the space sb.append("%20"); // for the remamining part, also convert ' ' to "%20". for (int i = pos+1; i < str.length(); i++) { if (str.charAt(i) == ' ') sb.append("%20"); else sb.append(str.charAt(i)); } str = sb.toString(); } ===== end insert ===== // done return str; } // fixURI(String):String
21-08-2008