Author: markt
Date: Thu Jul  6 13:39:21 2017
New Revision: 1801049

URL: http://svn.apache.org/viewvc?rev=1801049&view=rev
Log:
Refactor to avoid FindBugs NPE warning

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JavacErrorDetail.java

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JavacErrorDetail.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JavacErrorDetail.java?rev=1801049&r1=1801048&r2=1801049&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JavacErrorDetail.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JavacErrorDetail.java 
Thu Jul  6 13:39:21 2017
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -48,7 +48,7 @@ public class JavacErrorDetail {
     /**
      * Constructor.
      *
-     * @param javaFileName The name of the Java file in which the 
+     * @param javaFileName The name of the Java file in which the
      * compilation error occurred
      * @param javaLineNum The compilation error line number
      * @param errMsg The compilation error message
@@ -66,7 +66,7 @@ public class JavacErrorDetail {
     /**
      * Constructor.
      *
-     * @param javaFileName The name of the Java file in which the 
+     * @param javaFileName The name of the Java file in which the
      * compilation error occurred
      * @param javaLineNum The compilation error line number
      * @param jspFileName The name of the JSP file from which the Java source
@@ -82,15 +82,15 @@ public class JavacErrorDetail {
             int jspBeginLineNum,
             StringBuilder errMsg,
             JspCompilationContext ctxt) {
-        
+
         this(javaFileName, javaLineNum, errMsg);
         this.jspFileName = jspFileName;
         this.jspBeginLineNum = jspBeginLineNum;
-        
+
         if (jspBeginLineNum > 0 && ctxt != null) {
             InputStream is = null;
             FileInputStream  fis = null;
-            
+
             try {
                 // Read both files in, so we can inspect them
                 JarFile jarFile = null;
@@ -98,31 +98,28 @@ public class JavacErrorDetail {
                 if (tagJarResource != null) {
                     jarFile = tagJarResource.getJarFile();
                 }
-                try {
-                    is = JspUtil.getInputStream(jspFileName, jarFile, ctxt, 
null);
-                } catch (JasperException e) {
-                    // Ignore: Exception is never thrown.
-                }
-                
+
+                is = JspUtil.getInputStream(jspFileName, jarFile, ctxt, null);
+
                 String[] jspLines = readFile(is);
-    
+
                 fis = new FileInputStream(ctxt.getServletJavaFileName());
                 String[] javaLines = readFile(fis);
-    
+
                 if (jspLines.length < jspBeginLineNum) {
                     // Avoid ArrayIndexOutOfBoundsException
                     // Probably bug 48498 but could be some other cause
                     jspExtract = Localizer.getMessage("jsp.error.bug48498");
                     return;
                 }
-                
+
                 // If the line contains the opening of a multi-line scriptlet
                 // block, then the JSP line number we got back is probably
                 // faulty.  Scan forward to match the java line...
                 if (jspLines[jspBeginLineNum-1].lastIndexOf("<%") >
                     jspLines[jspBeginLineNum-1].lastIndexOf("%>")) {
                     String javaLine = javaLines[javaLineNum-1].trim();
-    
+
                     for (int i=jspBeginLineNum-1; i<jspLines.length; i++) {
                         if (jspLines[i].indexOf(javaLine) != -1) {
                             // Update jsp line number
@@ -131,13 +128,13 @@ public class JavacErrorDetail {
                         }
                     }
                 }
-    
+
                 // copy out a fragment of JSP to display to the user
                 StringBuilder fragment = new StringBuilder(1024);
                 int startIndex = Math.max(0, this.jspBeginLineNum-1-3);
                 int endIndex = Math.min(
                         jspLines.length-1, this.jspBeginLineNum-1+3);
-    
+
                 for (int i=startIndex;i<=endIndex; ++i) {
                     fragment.append(i+1);
                     fragment.append(": ");
@@ -145,7 +142,9 @@ public class JavacErrorDetail {
                     fragment.append(Constants.NEWLINE);
                 }
                 jspExtract = fragment.toString();
-    
+
+            } catch (JasperException je) {
+                // Exception is never thrown - ignore
             } catch (IOException ioe) {
                 // Can't read files - ignore
             } finally {
@@ -179,7 +178,7 @@ public class JavacErrorDetail {
 
     /**
      * Gets the compilation error line number.
-     * 
+     *
      * @return Compilation error line number
      */
     public int getJavaLineNumber() {
@@ -215,7 +214,7 @@ public class JavacErrorDetail {
     public String getErrorMessage() {
         return this.errMsg.toString();
     }
-    
+
     /**
      * Gets the extract of the JSP that corresponds to this message.
      *
@@ -224,7 +223,7 @@ public class JavacErrorDetail {
     public String getJspExtract() {
         return this.jspExtract;
     }
-    
+
     /**
      * Reads a text file from an input stream into a String[]. Used to read in
      * the JSP and generated Java file when generating error messages.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to