View | Details | Raw Unified | Return to bug 141522 | Differences between
and this patch

Collapse All | Expand All

(-)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
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-2 / +81 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
			"---" + File.separator + "X.java because of an IOException: Regular file " +
2919
			"---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "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
  	String tentativeOutputDirNameTail = 
2929
      	File.separator + "f/out";
2930
	this.runConformTest(
2931
		new String[] {
2932
			"X.java",
2933
			"public class X {}",
2934
			"f", // create simple file f
2935
			""
2936
        },
2937
        "\"" + OUTPUT_DIR +  File.separator + "X.java\""
2938
        + " -1.5 -g -preserveAllLocals"
2939
        + " -d \"" + OUTPUT_DIR + tentativeOutputDirNameTail + "\"",
2940
		"", 
2941
		"No .class file created for file X.class in ---OUTPUT_DIR_PLACEHOLDER" +
2942
			"---" + tentativeOutputDirNameTail + " because of an IOException: " +
2943
			"Could not create output directory ---OUTPUT_DIR_PLACEHOLDER---" + 
2944
			tentativeOutputDirNameTail + "\n",
2945
		true);
2946
}
2947
// suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=141522
2948
// only checking messages (the bug itself involves concurrent access to
2949
// the file system and a true test case would call for instrumented
2950
// code)
2951
public void test055(){
2952
  	String tentativeOutputDirNameTail = 
2953
      	File.separator + "out";
2954
  	File outputDirectory = new File(OUTPUT_DIR + tentativeOutputDirNameTail);
2955
  	outputDirectory.mkdirs();
2956
  	outputDirectory.setReadOnly();
2957
	this.runConformTest(
2958
		new String[] {
2959
			"p/X.java",
2960
			"package p;\n" +
2961
			"public class X {}",
2962
        },
2963
        "\"" + OUTPUT_DIR +  File.separator + "p/X.java\""
2964
        + " -1.5 -g -preserveAllLocals"
2965
        + " -d \"" + OUTPUT_DIR + tentativeOutputDirNameTail + "\"",
2966
		"", 
2967
		"No .class file created for file p" + File.separator + "X.class in " +
2968
			"---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "out because of " +
2969
			"an IOException: Could not create subdirectory p into output directory " +
2970
			"---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "out\n",
2971
		false /* do not flush output directory */);
2972
}
2973
// suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=141522
2974
// only checking messages (the bug itself involves concurrent access to
2975
// the file system and a true test case would call for instrumented
2976
// code)
2977
public void test056(){
2978
  	String tentativeOutputDirNameTail = 
2979
      	File.separator + "out";
2980
	this.runConformTest(
2981
		new String[] {
2982
			"p/X.java",
2983
			"package p;\n" +
2984
			"public class X {}",
2985
			"out/p", // create simple file out/p
2986
			""
2987
        },
2988
        "\"" + OUTPUT_DIR +  File.separator + "p/X.java\""
2989
        + " -1.5 -g -preserveAllLocals"
2990
        + " -d \"" + OUTPUT_DIR + tentativeOutputDirNameTail + "\"",
2991
		"", 
2992
		"No .class file created for file p" + File.separator + "X.class in " +
2993
			"---OUTPUT_DIR_PLACEHOLDER---" + tentativeOutputDirNameTail + 
2994
			" because of an IOException: Regular file ---OUTPUT_DIR_PLACEHOLDER---" + 
2995
			tentativeOutputDirNameTail + File.separator + "p cannot be used as " +
2996
			"output directory\n",
2997
		true);
2919
}
2998
}
2920
public static Class testClass() {
2999
public static Class testClass() {
2921
	return BatchCompilerTest.class;
3000
	return BatchCompilerTest.class;

Return to bug 141522