United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6506304 java.net.MalformedURLException: unknown protocol: c
JDK-6506304 : java.net.MalformedURLException: unknown protocol: c

Details
Type:
Bug
Submit Date:
2006-12-19
Status:
Resolved
Updated Date:
2012-06-08
Project Name:
JDK
Resolved Date:
2009-03-05
Component:
xml
OS:
windows_xp
Sub-Component:
jaxp
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
1.4.0 (1.4)

Related Reports
Backport:
Backport:
Backport:
Backport:

Sub Tasks

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

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
                                     
2008-08-21
EVALUATION

Reassign the issue to me. 

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

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

Fixed in jaxp 1.4 on java.net. Will request for integration into jdk6 update release.
                                     
2009-03-05
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.
                                     
2009-03-06



Hardware and Software, Engineered to Work Together