@@ -119,11 +119,14 @@ public void test_openOutputStream_exists() throws Exception {
119119 public void test_openOutputStream_existsButIsDirectory () throws Exception {
120120 File directory = new File (getTestDirectory (), "subdir" );
121121 directory .mkdirs ();
122+ FileOutputStream out = null ;
122123 try {
123- FileUtils .openOutputStream (directory );
124+ out = FileUtils .openOutputStream (directory );
124125 fail ();
125126 } catch (IOException ioe ) {
126127 // expected
128+ } finally {
129+ IOUtils .closeQuietly (out );
127130 }
128131 }
129132
@@ -140,12 +143,23 @@ public void test_openOutputStream_notExists() throws Exception {
140143 }
141144
142145 public void test_openOutputStream_notExistsCannotCreate () throws Exception {
143- File file = new File (getTestDirectory (), "a/:#$!/test.txt" ); // empty path segment is bad directory name
146+ // according to Wikipedia, most filing systems have a 256 limit on filename
147+ String longStr =
148+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
149+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
150+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
151+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
152+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
153+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" ; // 300 chars
154+ File file = new File (getTestDirectory (), "a/" + longStr + "/test.txt" );
155+ FileOutputStream out = null ;
144156 try {
145- FileUtils .openOutputStream (file );
157+ out = FileUtils .openOutputStream (file );
146158 fail ();
147159 } catch (IOException ioe ) {
148160 // expected
161+ } finally {
162+ IOUtils .closeQuietly (out );
149163 }
150164 }
151165
0 commit comments