Name: rmT116609 Date: 02/06/2003 FULL PRODUCT VERSION : java version "1.4.1" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21) Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode) FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : As shown in the example code, "file" URLs can't be written to. There are work-arounds, but they suffer from limitations. Adding custom handling for the "file" protocol defeats the purpose of the abstraction we are trying to hide behind. Adding an enhanced protocol handler seems workable, but the case for this being supported "out-of-the-box" is pretty strong. It would be different if the protocol was rarely used or had issues with output semantics. Neither is true. Whether or not any behavior is changed, additional documentation is needed about what protocols are supported by the default handlers. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Create a File URL 2. Open it 3. Try to get an OutputStream EXPECTED VERSUS ACTUAL BEHAVIOR : Expected: FileURLConnection should support output. Failing that, it should throw an UnsupportedOperationException when setDoOutput(true) is invoked. Actual: An UnknownServiceException is thrown when getOutputStream() is invoked. ERROR MESSAGES/STACK TRACES THAT OCCUR : d:\DOCUME~1\ccox\LOCALS~1\Temp\foo31795bar can be written to true Exception in thread "main" java.net.UnknownServiceException: protocol doesn't support output at java.net.URLConnection.getOutputStream(URLConnection.java:679) at Test.main(Test.java:13) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.io.*; import java.net.*; public class Test { public static void main(String[] args) throws Exception { File file = File.createTempFile("foo","bar"); System.out.println(file + " can be written to " + file.canWrite()); URLConnection con = file.toURL().openConnection(); con.setDoOutput(true); PrintWriter out = new PrintWriter(con.getOutputStream()); out.write("Test"); out.close(); } } ---------- END SOURCE ---------- CUSTOMER WORKAROUND : Either a) Add special handling for file URLs or b) Install a protocol handler See the following for discussion: http://forum.java.sun.com/thread.jsp?forum=31&thread=290300 (Review ID: 180944) ======================================================================
|