From: markt Date: Tue, 22 Feb 2011 16:38:39 +0000 (+0000) Subject: Test before generating debug log messages X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4abdb4b2091a72287a4048fd75a201625bd78a01;p=tomcat7.0 Test before generating debug log messages Fix FindBugs issues for File.delete() return value git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1073393 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index 7b9e03c4f..28b4c2ad0 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -271,7 +271,14 @@ public abstract class Compiler { } } // Remove the generated .java file - new File(javaFileName).delete(); + File file = new File(javaFileName); + if (file.exists()) { + if (!file.delete()) { + log.warn(Localizer.getMessage( + "jsp.warning.compiler.javafile.delete.fail", + file.getAbsolutePath())); + } + } throw e; } finally { if (writer != null) { @@ -451,7 +458,8 @@ public abstract class Compiler { } uc.getInputStream().close(); } catch (Exception e) { - log.debug("Problem accessing resource. Treat as outdated.", e); + if (log.isDebugEnabled()) + log.debug("Problem accessing resource. Treat as outdated.", e); return true; } @@ -514,7 +522,9 @@ public abstract class Compiler { return true; } } catch (Exception e) { - log.debug("Problem accessing resource. Treat as outdated.", e); + if (log.isDebugEnabled()) + log.debug("Problem accessing resource. Treat as outdated.", + e); return true; } } @@ -551,7 +561,13 @@ public abstract class Compiler { File classFile = new File(classFileName); if (log.isDebugEnabled()) log.debug("Deleting " + classFile); - classFile.delete(); + if (classFile.exists()) { + if (!classFile.delete()) { + log.warn(Localizer.getMessage( + "jsp.warning.compiler.classfile.delete.fail", + classFile.getAbsolutePath())); + } + } } } catch (Exception e) { // Remove as much as possible, ignore possible exceptions @@ -562,7 +578,13 @@ public abstract class Compiler { File javaFile = new File(javaFileName); if (log.isDebugEnabled()) log.debug("Deleting " + javaFile); - javaFile.delete(); + if (javaFile.exists()) { + if (!javaFile.delete()) { + log.warn(Localizer.getMessage( + "jsp.warning.compiler.javafile.delete.fail", + javaFile.getAbsolutePath())); + } + } } } catch (Exception e) { // Remove as much as possible, ignore possible exceptions @@ -576,7 +598,13 @@ public abstract class Compiler { File classFile = new File(classFileName); if (log.isDebugEnabled()) log.debug("Deleting " + classFile); - classFile.delete(); + if (classFile.exists()) { + if (!classFile.delete()) { + log.warn(Localizer.getMessage( + "jsp.warning.compiler.classfile.delete.fail", + classFile.getAbsolutePath())); + } + } } } catch (Exception e) { // Remove as much as possible, ignore possible exceptions diff --git a/java/org/apache/jasper/resources/LocalStrings.properties b/java/org/apache/jasper/resources/LocalStrings.properties index e8088ddae..ac24d87a2 100644 --- a/java/org/apache/jasper/resources/LocalStrings.properties +++ b/java/org/apache/jasper/resources/LocalStrings.properties @@ -227,6 +227,8 @@ jsp.error.bad_string_char=Cannot extract a char from a zero length array jsp.warning.compiler.class.cantcreate=Can't create an instance of specified compiler plugin class {0} due to {1}. Will default to Sun Java Compiler. jsp.warning.compiler.class.notfound=Specified compiler plugin class {0} not found. Will default to Sun Java Compiler. jsp.warning.compiler.path.notfound=Specified compiler path {0} not found. Will default to system PATH. +jsp.warning.compiler.classfile.delete.fail=Failed to delete generated class file [{0}] +jsp.warning.compiler.javafile.delete.fail=Failed to delete generated Java file [{0}] jsp.error.jspc.uriroot_not_dir=The -uriroot option must specify a pre-existing directory jsp.error.jspc.missingTarget=Missing target: Must specify -webapp or -uriroot, or one or more JSP pages jsp.error.jspc.no_uriroot=The uriroot is not specified and cannot be located with the specified JSP file(s)