JDK-4234961 : Windows NT filename text encoding doesn't handle illegal chars
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 1.1.8
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-05-03
  • Updated: 2006-04-27
  • Resolved: 2006-04-27
Related Reports
Relates :  
Relates :  
Description
Name: krT82822			Date: 05/03/99


Background:

If Windows NT's file system encounters a file with illegal characters (eg, \ / etc) it converts the illegal chars to   0xF0xx. . .

    [reflects correction vs. original, based on later user comment:  "I said the  characters are 0xFFxx, but they're actually 0xF0xx."]

Files with illegal characters can be generated on the Mac.

Somewhere in the Java encoding, these special characters get converted to '?' (0x3F).  This makes it impossible to open the file with an
InputStream or Reader object...

Code:

This application just uses a FileDialog to select a file.  It then tries to open it with a FileReader which will fail with a FileNotFoundException.
You'll need to create a file with illegal chars yourself.

import java.awt.*;
import java.io.*;

public class TrivialApplication {

        public static void main(String args[]) 
	{
		Frame f = new Frame();
		f.pack();
		
		FileDialog d = new FileDialog(f);
		d.setVisible(true);
		
		String javaPath;
		System.out.println(javaPath = d.getFile());
		
		try
		{
			FileReader inStream = new FileReader(javaPath);
			inStream.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}

Sample output:

[d:\araxidev\javahacks\illegalntchartest]java -version
java version "1.1.8"

[d:\araxidev\javahacks\illegalntchartest]java -fullversion
java full version "JDK1.1.8K"

[d:\araxidev\javahacks\illegalntchartest]java -classpath d:\araxioem\private\jdk
1.1.8\lib\classes.zip;AppClasses.jar TrivialApplication
90??? fromHell.pdf
java.io.FileNotFoundException: 90??? fromHell.pdf
        at java.io.FileInputStream.<init>(FileInputStream.java:56)
        at java.io.FileReader.<init>(FileReader.java:35)
        at TrivialApplication.main(TrivialApplication.java)
(Review ID: 57670) 
======================================================================

Comments
EVALUATION As suggested above, use java.nio.charset.spi to have customized version of charset.
27-04-2006

WORK AROUND Name: krT82822 Date: 05/03/99 None. ======================================================================
08-09-2004

EVALUATION The new character converter SPI, rfe #4313884 for merlin/jdk1.4 provides public access to a method for setting the substitution char (or chars). So, for example, it should be possible for an application developer to implement their own policy with regard to how characters which cannot be mapped in a given encoding are substituted (or not). Ian.Little@Ireland 12/21/2000
21-12-2000