4,563,197 th visitor since 2017.2.1 ( Today : 91 )
Programming
No. 399
Name. swindler
Subject. If URI scheme is file and URL is not UTF-8 encoded, the ParseUtil.decode throws
Main Cate. Java
Sub Cate.
Date. 2007-10-13 10:16
Hit. 6167 (211.36.27.8)
File.
Bug ID: 6522294
Votes 0
Synopsis If URI scheme is file and URL is not UTF-8 encoded, the ParseUtil.decode throws an Exception
Category java:classes_net
Reported Against
Release Fixed 7(b10)
State Closed, fixed
Related Bugs 6521166
Submit Date 07-FEB-2007
Description By using the sun.net.www.protocol.file.Handler.openConnection() the sun.net.www.ParseUtil.decode() throws an java.lang.IllegalArgumentException if an URL is used which has been encoded with the default encoding of the platform rather than UTF-8 and if the URI scheme is "file".

There is no problem if the URL is UTF-8 encoded and URI scheme is "file".

There is no problem anymore [to be exact 1.5.0_07+ is required, see CR 6274990] when the ParseUtil.decode() is the URL is not UTF-8 encoded, but run through an HttpURLConnection (if the URI scheme is "http").

$ java -showversion JEditorPaneTest
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)

java.lang.IllegalArgumentException
at sun.net.www.ParseUtil.decode(ParseUtil.java:185)
at sun.net.www.protocol.file.Handler.openConnection(Handler.java:63)
at sun.net.www.protocol.file.Handler.openConnection(Handler.java:55)
at java.net.URL.openConnection(URL.java:945)
at javax.swing.JEditorPane.getStream(JEditorPane.java:769)
at javax.swing.JEditorPane.setPage(JEditorPane.java:418)
at javax.swing.JEditorPane.setPage(JEditorPane.java:922)
at javax.swing.JEditorPane.<init>(JEditorPane.java:258)
at JEditorPaneTest.<init>(JEditorPaneTest.java:18)
at JEditorPaneTest.main(JEditorPaneTest.java:35)

$ java -showversion JEditorPaneTest
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Server VM (build 1.5.0_11-b03, mixed mode)

java.lang.IllegalArgumentException
at sun.net.www.ParseUtil.decode(ParseUtil.java:185)
at sun.net.www.protocol.file.Handler.openConnection(Handler.java:63)
at sun.net.www.protocol.file.Handler.openConnection(Handler.java:55)
at java.net.URL.openConnection(URL.java:943)
at javax.swing.JEditorPane.getStream(JEditorPane.java:685)
at javax.swing.JEditorPane.setPage(JEditorPane.java:406)
at javax.swing.JEditorPane.setPage(JEditorPane.java:790)
at javax.swing.JEditorPane.<init>(JEditorPane.java:251)
at JEditorPaneTest.<init>(JEditorPaneTest.java:18)
at JEditorPaneTest.main(JEditorPaneTest.java:35)

The sourcecode to reproduce the problem is attached to the bug report (see also workaround).
Posted Date : 2007-02-07 12:13:03.0


Work Around Don't use localized characters in URLs

OR

use
private static final String url = "file:///m\u00FCnchen.html";
JEditorPane editorPane = new JEditorPane(new URI(url).toASCIIString());
// m%C3%BCnchen.html

rather than
private static final String url = "file:///m%FCnchen.html";
JEditorPane editorPane = new JEditorPane(url);

Evaluation sun.net.www.protocol.file.Handler calls sun.net.www.ParseUtil.decode to decode any percent encoded characters. This fails with IllegalArgumentException as the internal implementation of the file protocol handler expects that any percent encoded characters are UTF-8 encoded.

The http protocol handler does not have this problem as it does not decode the percent encoded characters in the URL. It simply sends a request to server with the URL path as it. It is up to the server to know how to handle this. The file protocol handler on the other hand needs to decode the percent encoded characters as the requested resource will be accessed from the local machine.

The recommended way to manage the encoding and decoding of URLs is to use URI, and to convert between these two classes using toURI() and URI.toURL(), as suggested in the workaround section. The java.net.URI class specifies that any percent encoded characters should use UTF-8.

So the solution is to use the URI class, that being said the exception that is being thrown (IllegalArgumentException) does not clearly identify what the problem is. We could change the internally implementation of the file protocol handler to report a more clear explaination of the problem.

The IllegalArgumentException now contains a more detailed message about the cause of the problem. For compatibility reasons an IAE is still being thrown.
Posted Date : 2007-03-06 10:39:21.0




[바로가기 링크] : http://coolx.net/cboard/develop/399



swindler bugs.sun.com 에 올라온 버그다.
좋지 않다. 저기 제시된 해결책으로 해결이 안 된단 말이지 ㅠㅠ
2007-10-13
Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog