Nathan Beyer wrote:
This commit seems contradictory to the specification. All JREs must
support UTF-8 as an encoding, so the UnsupportedEncodingException
should never happen.

I think the code should throw new AssertionError(e) in the catch block.

I'm not sure I'd call it contradictory to the spec - the exception needs to be caught as it is declared by the String constructor being called, whether it should happen or not. How it is handled is up to us - perhaps an AssertionError would be better here to indicate that we have entered a code block that should be unreachable. I don't feel strongly either way so am happy to go with whatever the consensus feeling on this is.

Regards,
Oliver

Thoughts?

-Nathan

On Tue, May 12, 2009 at 11:23 AM,  <[email protected]> wrote:
Author: odeakin
Date: Tue May 12 16:23:08 2009
New Revision: 773966

URL: http://svn.apache.org/viewvc?rev=773966&view=rev
Log:
When constructing the exception, make sure the error message is in an encoding 
where it will be readable on non-ASCII platforms once printed.

Modified:
   
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java

Modified: 
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
URL: 
http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java?rev=773966&r1=773965&r2=773966&view=diff
==============================================================================
--- 
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
 (original)
+++ 
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
 Tue May 12 16:23:08 2009
@@ -20,6 +20,7 @@
 import java.io.FileDescriptor;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;

 /**
 * This is the portable implementation of the file system interface.
@@ -235,7 +236,11 @@
               }
               long handler = openImpl(fileName, mode);
               if (handler < 0) {
-                       throw new FileNotFoundException(new String(fileName));
+                    try {
+                        throw new FileNotFoundException(new String(fileName, 
"UTF-8"));
+                    } catch (java.io.UnsupportedEncodingException e) {
+                        throw new FileNotFoundException(new String(fileName));
+                    }
               }
               return handler;
       }





--
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

Reply via email to