Fix the last of the high priority FindBugs warnings
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 18 Jan 2011 18:57:45 +0000 (18:57 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 18 Jan 2011 18:57:45 +0000 (18:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1060538 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/JspC.java
java/org/apache/jasper/resources/LocalStrings.properties
java/org/apache/naming/factory/webservices/ServiceProxy.java
java/org/apache/tomcat/util/buf/StringCache.java
res/findbugs/filter-false-positives.xml

index 0300a51..22e43de 100644 (file)
@@ -151,7 +151,6 @@ public class JspC implements Options {
         insertBefore.add("<ejb-local-ref>");
     }
 
-    protected static int die;
     protected String classPath = null;
     protected URLClassLoader loader = null;
     protected boolean trimSpaces = false;
@@ -251,8 +250,9 @@ public class JspC implements Options {
         if (arg.length == 0) {
             System.out.println(Localizer.getMessage("jspc.usage"));
         } else {
+            JspC jspc = null;
             try {
-                JspC jspc = new JspC();
+                jspc = new JspC();
                 jspc.setArgs(arg);
                 if (jspc.helpNeeded) {
                     System.out.println(Localizer.getMessage("jspc.usage"));
@@ -261,8 +261,8 @@ public class JspC implements Options {
                 }
             } catch (JasperException je) {
                 System.err.println(je);
-                if (die != NO_DIE_LEVEL) {
-                    System.exit(die);
+                if (jspc != null && jspc.dieLevel != NO_DIE_LEVEL) {
+                    System.exit(jspc.dieLevel);
                 }
             }
         }
@@ -279,7 +279,6 @@ public class JspC implements Options {
         String tok;
 
         dieLevel = NO_DIE_LEVEL;
-        die = dieLevel;
 
         while ((tok = nextArg()) != null) {
             if (tok.equals(SWITCH_VERBOSE)) {
@@ -341,7 +340,6 @@ public class JspC implements Options {
                 } catch (NumberFormatException nfe) {
                     dieLevel = DEFAULT_DIE_LEVEL;
                 }
-                die = dieLevel;
             } else if (tok.equals(SWITCH_HELP)) {
                 helpNeeded = true;
             } else if (tok.equals(SWITCH_POOLING)) {
@@ -804,8 +802,8 @@ public class JspC implements Options {
      * includes.
      */
     public void setUriroot( String s ) {
-        if( s==null ) {
-            uriRoot = s;
+        if (s == null) {
+            uriRoot = null;
             return;
         }
         try {
@@ -1097,8 +1095,12 @@ public class JspC implements Options {
         fis.close();
         fos.close();
 
-        webXml2.delete();
-        (new File(webxmlFile)).delete();
+        if(!webXml2.delete() && log.isDebugEnabled())
+            log.debug(Localizer.getMessage("jspc.delete.fail",
+                    webXml2.toString()));
+        
+        if (!(new File(webxmlFile)).delete() && log.isDebugEnabled())
+            log.debug(Localizer.getMessage("jspc.delete.fail", webxmlFile));
 
     }
     
index cae2529..e8088dd 100644 (file)
@@ -296,6 +296,7 @@ jspc.error.jasperException=error-the file ''{0}'' generated the following parse
 jspc.error.generalException=ERROR-the file ''{0}'' generated the following general exception:
 jspc.error.fileDoesNotExist=The file argument ''{0}'' does not exist
 jspc.error.emptyWebApp=-webapp requires a trailing file argument
+jspc.delete.fail=Failed to delete file [{0}]
 jsp.error.library.invalid=JSP page is invalid according to library {0}: {1}
 jsp.error.tlvclass.instantiation=Failed to load or instantiate TagLibraryValidator class: {0}
 jsp.error.tlv.invalid.page=Validation error messages from TagLibraryValidator for {0} in {1}
index 2bf07a6..5d2b212 100644 (file)
@@ -75,9 +75,11 @@ public class ServiceProxy
     }
 
     /**
-     * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+     * @see InvocationHandler#invoke(Object, Method, Object[])
      */
-    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args)
+            throws Throwable {
 
         if (portQNameClass.equals(method)) {
             return getProxyPortQNameClass(args);
@@ -99,6 +101,7 @@ public class ServiceProxy
      * @return Returns the correct Port
      * @throws ServiceException if port's QName is an unknown Port (not defined in WSDL).
      */
+    @SuppressWarnings("unchecked")
     private Object getProxyPortQNameClass(Object[] args)
     throws ServiceException {
         QName name = (QName) args[0];
index ce74e2b..23cd270 100644 (file)
@@ -236,7 +236,7 @@ public class StringCache {
                         for (Entry<ByteEntry,int[]> item : bcStats.entrySet()) {
                             ByteEntry entry = item.getKey();
                             int[] countA = item.getValue();
-                            Integer count = new Integer(countA[0]);
+                            Integer count = Integer.valueOf(countA[0]);
                             // Add to the list for that count
                             ArrayList<ByteEntry> list = tempMap.get(count);
                             if (list == null) {
@@ -353,7 +353,7 @@ public class StringCache {
                         for (Entry<CharEntry,int[]> item : ccStats.entrySet()) {
                             CharEntry entry = item.getKey();
                             int[] countA = item.getValue();
-                            Integer count = new Integer(countA[0]);
+                            Integer count = Integer.valueOf(countA[0]);
                             // Add to the list for that count
                             ArrayList<CharEntry> list = tempMap.get(count);
                             if (list == null) {
@@ -518,7 +518,7 @@ public class StringCache {
 
         int i = 0;
         while (true) {
-            i = (b + a) / 2;
+            i = (b + a) >>> 1;
             int result = compare(name, array[i].name);
             if (result == 1) {
                 a = i;
@@ -612,7 +612,7 @@ public class StringCache {
 
         int i = 0;
         while (true) {
-            i = (b + a) / 2;
+            i = (b + a) >>> 1;
             int result = compare(name, array[i].name);
             if (result == 1) {
                 a = i;
index 1ab467c..95969b3 100644 (file)
 <FindBugsFilter>
   <!--  Considered to be false positives -->
   <Match>
+    <!-- JNI library can only be loaded once so statics are appropriate -->
+    <Class name="org.apache.catalina.core.AprLifecycleListener" />
+    <Bug code="ST" />
+  </Match>
+  <Match>
     <!-- Have to trigger GC for leak detection to work. Clearly documented -->
     <Class name="org.apache.catalina.core.StandardHost" />
     <Method name="findReloadedContextMemoryLeaks" />
@@ -28,7 +33,7 @@
     <Bug code="MSF" />
   </Match>
   <Match>
-    <!-- Catalina isn'y used when embedding -->
+    <!-- Catalina isn't used when embedding -->
     <Class name="org.apache.catalina.startup.Catalina" />
     <Method name="stopServer" />
     <Bug code="Dm" />
     <Bug code="NS"/>
   </Match>
   <Match>
+    <!-- JspC will not be used under a security manager -->
+    <Class name="org.apache.jasper.JspC"/>
+    <Method name="initClassLoader"/>
+    <Bug code="DP" />
+  </Match>
+  <Match>
+    <!-- Parser config is static so statics are appropriate -->
+    <Class name="org.apache.jasper.JspC"/>
+    <Method name="setValidateXml"/>
+    <Bug code="ST" />
+  </Match>
+  <Match>
     <!-- Simpler to catch Exception than to create dummy implementations of the
          necessary exception hierarchy -->
     <Class name="org.apache.naming.factory.SendMailFactory$1" />
     <Bug code="DE" />
   </Match>
   <Match>
+    <!-- Simpler to catch Exception than to create dummy implementations of the
+         necessary exception hierarchy -->
+    <Class name="org.apache.naming.factory.webservices.ServiceProxy" />
+    <Method name="&lt;init&gt;"/>
+    <Bug code="ST" />
+  </Match>
+  <Match>
     <!-- Class name needs to start with a lower case letter in this case -->
     <Class name="org.apache.naming.java.javaURLContextFactory" />
     <Bug code="Nm" />
     <Bug code="NP" />
   </Match>
   <Match>
+    <!-- Whilst cache is global there may be multiple instances (one per     -->
+    <!-- server so statics are appropriate -->
+    <Class name="org.apache.tomcat.util.buf.StringCache"/>
+    <Bug code="ST" />
+  </Match>
+  <Match>
     <!-- Test really is for the same object rather than equality -->
     <Class name="org.apache.tomcat.util.digester.Digester"/>
     <Method name="updateBodyText"/>