fix-NPE-on-invalid-path.diff
src/com/goldencode/p2j/util/logging/LoggingUtil.java 2023-05-29 10:03:14 +0000 | ||
---|---|---|
204 | 204 |
* @param filePath |
205 | 205 |
* File path for the log. |
206 | 206 |
* |
207 |
* @return <code>true</code> if the process can write to the file path, <code>false</code> otherwise. |
|
207 |
* @throws ConfigurationException |
|
208 |
* If the process can't create or write to the file path. |
|
208 | 209 |
*/ |
209 |
public static boolean canWriteToPath(String filePath)
|
|
210 |
public static void canWriteToPath(String filePath)
|
|
210 | 211 |
throws ConfigurationException |
211 | 212 |
{ |
212 | 213 |
try |
... | ... | |
219 | 220 |
{ |
220 | 221 |
if (!dir.mkdirs()) |
221 | 222 |
{ |
222 |
LOG.warning("Cannot create dir for log path " + filePath); |
|
223 |
return false; |
|
223 |
throw new ConfigurationException("Cannot create dir for log path " + filePath); |
|
224 | 224 |
} |
225 | 225 |
} |
226 | 226 | |
227 | 227 |
if (location.exists() && (!location.isFile() || !location.canWrite())) |
228 | 228 |
{ |
229 |
LOG.warning("The provided log path is not a file or is not writable: " + filePath); |
|
230 |
return false; |
|
229 |
throw new ConfigurationException("The provided log path is not a file or is not writable: " + filePath); |
|
231 | 230 |
} |
232 | 231 | |
233 | 232 |
if (!location.exists()) |
... | ... | |
237 | 236 |
if (!location.isFile() || !location.canWrite()) |
238 | 237 |
{ |
239 | 238 |
location.delete(); |
240 |
LOG.warning("The provided log path is not a file or is not writable: " + filePath); |
|
241 |
return false; |
|
239 |
throw new ConfigurationException("The provided log path is not a file or is not writable: " + filePath); |
|
242 | 240 |
} |
243 | 241 |
location.delete(); |
244 | 242 |
} |
245 | 243 |
else |
246 | 244 |
{ |
247 |
LOG.warning("The provided log path can't be created: " + filePath); |
|
248 |
return false; |
|
245 |
throw new ConfigurationException("The provided log path can't be created: " + filePath); |
|
249 | 246 |
} |
250 | 247 |
} |
251 | 248 |
} |
252 | 249 |
catch (Exception ex) |
253 | 250 |
{ |
254 |
LOG.warning("Exception in setting up the provided log file path " + filePath, ex);
|
|
251 |
throw new ConfigurationException("Exception in setting up the provided log file path " + filePath, ex);
|
|
255 | 252 |
} |
256 |
return true; |
|
257 | 253 |
} |
258 | 254 |
} |