Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 141522 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-2 / +82 lines)
Lines 2914-2921 Link Here
2914
        + " -1.5 -g -preserveAllLocals"
2914
        + " -1.5 -g -preserveAllLocals"
2915
        + " -d \"" + OUTPUT_DIR + File.separator + "X.java\"",
2915
        + " -d \"" + OUTPUT_DIR + File.separator + "X.java\"",
2916
		"", 
2916
		"", 
2917
		"No .class file created for file X.class in ---OUTPUT_DIR_PLACEHOLDER---/X.java because of an IOException: The output directory is a file : ---OUTPUT_DIR_PLACEHOLDER---/X.java\n",
2917
		"No .class file created for file X.class in ---OUTPUT_DIR_PLACEHOLDER" +
2918
        true);
2918
			"---/X.java because of an IOException: Regular file " +
2919
			"---OUTPUT_DIR_PLACEHOLDER---/X.java cannot be used " +
2920
			"as output directory\n",
2921
		true);
2922
}
2923
// suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=141522
2924
// only checking messages (the bug itself involves concurrent access to
2925
// the file system and a true test case would call for instrumented
2926
// code)
2927
public void test054(){
2928
	this.runConformTest(
2929
		new String[] {
2930
			"X.java",
2931
			"public class X {}",
2932
			"f", // create simple file f
2933
			""
2934
        },
2935
        "\"" + OUTPUT_DIR +  File.separator + "X.java\""
2936
        + " -1.5 -g -preserveAllLocals"
2937
        + " -d \"" + OUTPUT_DIR + "/f/out\"",
2938
		"", 
2939
		"No .class file created for file X.class in ---OUTPUT_DIR_PLACEHOLDER" +
2940
			"---/f/out because of an IOException: " +
2941
			"Could not create output directory ---OUTPUT_DIR_PLACEHOLDER---/f/out\n",
2942
		true);
2943
}
2944
// suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=141522
2945
// only checking messages (the bug itself involves concurrent access to
2946
// the file system and a true test case would call for instrumented
2947
// code)
2948
// this test only works on appropriate file systems
2949
public void test055(){
2950
	if (File.separatorChar == '/') {
2951
	  	String tentativeOutputDirNameTail = 
2952
	      	File.separator + "out";
2953
	  	File outputDirectory = new File(OUTPUT_DIR + tentativeOutputDirNameTail);
2954
	  	outputDirectory.mkdirs();
2955
	  	outputDirectory.setReadOnly(); 
2956
	  	// read-only directories do not prevent file creation 
2957
	  	// on under-gifted file systems
2958
		this.runConformTest(
2959
			new String[] {
2960
				"p/X.java",
2961
				"package p;\n" +
2962
				"public class X {}",
2963
	        },
2964
	        "\"" + OUTPUT_DIR +  File.separator + "p/X.java\""
2965
	        + " -1.5 -g -preserveAllLocals"
2966
	        + " -d \"" + OUTPUT_DIR + "/out\"",
2967
			"", 
2968
			"No .class file created for file p/X.class in " +
2969
				"---OUTPUT_DIR_PLACEHOLDER---/out because of " +
2970
				"an IOException: Could not create subdirectory p into output directory " +
2971
				"---OUTPUT_DIR_PLACEHOLDER---/out\n",
2972
			false /* do not flush output directory */);
2973
	}
2974
}
2975
// suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=141522
2976
// only checking messages (the bug itself involves concurrent access to
2977
// the file system and a true test case would call for instrumented
2978
// code)
2979
public void test056(){
2980
  	String tentativeOutputDirNameTail = 
2981
      	File.separator + "out";
2982
	this.runConformTest(
2983
		new String[] {
2984
			"p/X.java",
2985
			"package p;\n" +
2986
			"public class X {}",
2987
			"out/p", // create simple file out/p
2988
			""
2989
        },
2990
        "\"" + OUTPUT_DIR +  File.separator + "p/X.java\""
2991
        + " -1.5 -g -preserveAllLocals"
2992
        + " -d \"" + OUTPUT_DIR + tentativeOutputDirNameTail + "\"",
2993
		"", 
2994
		"No .class file created for file p/X.class in " +
2995
			"---OUTPUT_DIR_PLACEHOLDER---/out" + 
2996
			" because of an IOException: Regular file ---OUTPUT_DIR_PLACEHOLDER---" + 
2997
			"/out/p cannot be used as output directory\n",
2998
		true);
2919
}
2999
}
2920
public static Class testClass() {
3000
public static Class testClass() {
2921
	return BatchCompilerTest.class;
3001
	return BatchCompilerTest.class;
(-)compiler/org/eclipse/jdt/internal/compiler/messages.properties (-3 / +3 lines)
Lines 23-31 Link Here
23
compilation_internalError = Internal compiler error
23
compilation_internalError = Internal compiler error
24
24
25
### output
25
### output
26
output_isFile =  The output directory is a file : {0}
26
output_isFile =  Regular file {0} cannot be used as output directory
27
output_notValidAll =  The output directory {0} is not a valid directory name. All the directories cannot be created
27
output_notValidAll =  Could not create output directory {0}
28
output_notValid = The output directory ''{0}'' is not a valid directory name. The directory cannot be created
28
output_notValid = Could not create subdirectory {0} into output directory {1}
29
29
30
### problem
30
### problem
31
problem_noSourceInformation =
31
problem_noSourceInformation =
(-)compiler/org/eclipse/jdt/internal/compiler/ClassFile.java (-13 / +40 lines)
Lines 117-134 Link Here
117
			outputPath = outputPath.substring(0, outputPath.length() - 1);
117
			outputPath = outputPath.substring(0, outputPath.length() - 1);
118
		}
118
		}
119
		f = new File(outputPath);
119
		f = new File(outputPath);
120
		boolean checkFileType = false;
120
		if (f.exists()) {
121
		if (f.exists()) {
121
			if (!f.isDirectory()) {
122
		  	checkFileType = true; // pre-existed
122
				final String message = Messages.bind(Messages.output_isFile, f.getAbsolutePath());
123
				throw new IOException(message);
124
			}
125
		} else {
123
		} else {
126
			// we have to create that directory
124
			// we have to create that directory
127
			if (!f.mkdirs()) {
125
			if (!f.mkdirs()) {
128
				final String message = Messages.bind(Messages.output_notValidAll, f.getAbsolutePath());
126
			  	if (f.exists()) {
129
				throw new IOException(message);
127
			  	  	// someone else created f -- need to check its type
128
			  	  	checkFileType = true;
129
			  	} else {
130
			  	  	// no one could create f -- complain
131
    				throw new IOException(Messages.bind(
132
    					Messages.output_notValidAll, f.getAbsolutePath()));
133
			  	}
130
			}
134
			}
131
		}
135
		}
136
		if (checkFileType) {
137
		  	if (!f.isDirectory()) {
138
    			throw new IOException(Messages.bind(
139
    				Messages.output_isFile, f.getAbsolutePath()));
140
		  	}
141
		}
132
		StringBuffer outDir = new StringBuffer(outputPath);
142
		StringBuffer outDir = new StringBuffer(outputPath);
133
		outDir.append(fileSeparator);
143
		outDir.append(fileSeparator);
134
		StringTokenizer tokenizer =
144
		StringTokenizer tokenizer =
Lines 136-150 Link Here
136
		String token = tokenizer.nextToken();
146
		String token = tokenizer.nextToken();
137
		while (tokenizer.hasMoreTokens()) {
147
		while (tokenizer.hasMoreTokens()) {
138
			f = new File(outDir.append(token).append(fileSeparator).toString());
148
			f = new File(outDir.append(token).append(fileSeparator).toString());
149
		  	checkFileType = false; // reset
139
			if (f.exists()) {
150
			if (f.exists()) {
140
				// The outDir already exists, so we proceed the next entry
151
			  	checkFileType = true; // this is suboptimal, but it catches corner cases
141
				// System.out.println("outDir: " + outDir + " already exists.");
152
			  						  // in which a regular file pre-exists
142
			} else {
153
			} else {
143
				// Need to add the outDir
154
			// we have to create that directory
144
				if (!f.mkdir()) {
155
    			if (!f.mkdir()) {
145
					throw new IOException(Messages.bind(Messages.output_notValid, f.getName()));
156
    			  	if (f.exists()) {
146
				}
157
    			  	  	// someone else created f -- need to check its type
147
			}
158
    			  	  	checkFileType = true;
159
    			  	} else {
160
    			  	  	// no one could create f -- complain
161
        				throw new IOException(Messages.bind(
162
        					Messages.output_notValid, 
163
        						outDir.substring(outputPath.length() + 1, 
164
        							outDir.length() - 1),
165
        						outputPath));
166
    			  	}
167
    			}
168
			}
169
    		if (checkFileType) {
170
    		  	if (!f.isDirectory()) {
171
        			throw new IOException(Messages.bind(
172
        				Messages.output_isFile, f.getAbsolutePath()));
173
    		  	}
174
    		}
148
			token = tokenizer.nextToken();
175
			token = tokenizer.nextToken();
149
		}
176
		}
150
		// token contains the last one
177
		// token contains the last one

Return to bug 141522