FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The FileOutputStream constructor is throwing a FileNotFoundExeception when "long" paths or filenames are used. We have noticed slightly different behavior depending on the exact nature of the file/path.
For just file name (no path), the file name must be very long (~200 characters).
For relative paths, the path needs to be fairly long, but no individual path component or file name is unusually long.
For absolute paths, the exception is not thrown, but the file is not created.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The FileOutputStream should be created without error and the file should exist.
ACTUAL -
The FileOutputStream constructor throws an exception. With an absolute path, the constructor succeeds, but the file does not exist.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.FileNotFoundException: out\com.ascential.xmeta.persistence.impl.concrete.model.ConcreteRelationships\src\java\com\ascential\xmeta\persistence\impl\concrete\model\ConcreteRelationships\xmetagen\Fred123456.java (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at com.ascential.test.FileNotFoundTest.doTest(FileNotFoundTest.java:72)
at com.ascential.test.FileNotFoundTest.testWithRelativePaths(FileNotFoundTest.java:41)
at com.ascential.test.FileNotFoundTest.main(FileNotFoundTest.java:10)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package com.ascential.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class FileNotFoundTest {
public static void main(String[] args) {
testWithLongFileNames();
testWithRelativePaths();
testWithAbsolutePaths();
}
/**
* Demonstrate the problem with very long file names. This particular
* aspect of the issue is not terribly concerning to us, but may be
* related to the root cause.
*
*/
private static void testWithLongFileNames() {
String worksFileName = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345";
String failsFileName = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";
System.out.println("Testing with long file names:");
doTest(worksFileName);
doTest(failsFileName);
System.out.println("");
}
/**
* Demonstrates the problem using relative paths. None of the individual
* directory or file names are very long, but the problem still occurs.
*
*/
private static void testWithRelativePaths() {
String worksFileName ="out\\com.ascential.xmeta.persistence.impl.concrete.model.ConcreteRelationships\\src\\java\\com\\ascential\\xmeta\\persistence\\impl\\concrete\\model\\ConcreteRelationships\\xmetagen\\impl\\concrete\\model\\ConcreteRelationships\\xmetagen\\impl\\concrete\\model\\Fred123456.java";
String failsFileName = "out\\com.ascential.xmeta.persistence.impl.concrete.model.ConcreteRelationships\\src\\java\\com\\ascential\\xmeta\\persistence\\impl\\concrete\\model\\ConcreteRelationships\\xmetagen\\impl\\concrete\\model\\ConcreteRelationships\\xmetagen\\impl\\concrete\\model\\Fred1234567.java";
System.out.println("Testing with relative paths:");
doTest(worksFileName);
doTest(failsFileName);
System.out.println("");
}
/**
* Demonstrate the problem with absolute paths. The real concern here is
* that the second file appears to be opened successfully, but the file
* is not created.
*
*/
private static void testWithAbsolutePaths() {
String worksFileName ="c:\\views\\mtucker_xmeta_sv\\metadata_infrastructure\\framework\\out\\com.ascential.xmeta.persistence.impl.concrete.model.ConcreteRelationships\\src\\java\\com\\ascential\\xmeta\\persistence\\impl\\concrete\\model\\ConcreteRelationships\\xmetagen\\Fred12345678901234567890.java";
String failsFileName ="c:\\views\\mtucker_xmeta_sv\\metadata_infrastructure\\framework\\out\\com.ascential.xmeta.persistence.impl.concrete.model.ConcreteRelationships\\src\\java\\com\\ascential\\xmeta\\persistence\\impl\\concrete\\model\\ConcreteRelationships\\xmetagen\\Fred123456789012345678901.java";
System.out.println("Testing with absolute paths:");
doTest(worksFileName);
doTest(failsFileName);
System.out.println("");
}
private static void doTest(String fileName) {
File firstFile = new File(fileName);
if (firstFile.getParentFile() != null) {
firstFile.getParentFile().mkdirs();
}
System.out.println("Testing: " + fileName);
try {
FileOutputStream fos = new FileOutputStream(firstFile);
System.out.println(" file open succeeded");
} catch (FileNotFoundException e) {
System.out.println(" file open failed");
e.printStackTrace();
}
System.out.println(" exists: " + firstFile.exists());
System.out.println("");
}
}
---------- END SOURCE ----------
###@###.### 10/21/04 20:15 GMT