Author: kkolinko
Date: Sat Nov 22 12:14:11 2014
New Revision: 1641051

URL: http://svn.apache.org/r1641051
Log:
Use try-with-resources. Correct formatting, which includes indenting a nested 
block of code.
Followup to r1640976, r1640978

Modified:
    tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java
    tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java

Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java?rev=1641051&r1=1641050&r2=1641051&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java Sat Nov 
22 12:14:11 2014
@@ -631,10 +631,7 @@ class TagFileProcessor {
                         compiler.getCompilationContext().getTldResourcePath(
                             tagFileInfo.getTagInfo().getTagLibrary().getURI());
 
-                    Jar jar = null;
-                    try
-                    {
-                        jar = tldResourcePath.openJar();
+                    try (Jar jar = tldResourcePath.openJar()) {
 
                         if (jar != null) {
                             // Add TLD
@@ -643,8 +640,7 @@ class TagFileProcessor {
                             // Add Tag
                             
pageInfo.addDependant(jar.getURL(tagFilePath.substring(1)),
                                                   
Long.valueOf(jar.getLastModified(tagFilePath.substring(1))));
-                        }
-                        else {
+                        } else {
                             pageInfo.addDependant(tagFilePath,
                                                   
compiler.getCompilationContext().getLastModified(
                                                                                
                    tagFilePath));
@@ -652,11 +648,6 @@ class TagFileProcessor {
                     } catch (IOException ioe) {
                         throw new JasperException(ioe);
                     }
-                    finally
-                    {
-                        if(null != jar)
-                            jar.close(); // Jar.close does not "throw 
IOException" but probably should
-                    }
                 } else {
                     pageInfo.addDependant(tagFilePath,
                             compiler.getCompilationContext().getLastModified(

Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java?rev=1641051&r1=1641050&r2=1641051&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java Sat 
Nov 22 12:14:11 2014
@@ -124,105 +124,98 @@ class TagLibraryInfoImpl extends TagLibr
             tldResourcePath = generateTldResourcePath(uri, ctxt);
         }
 
-        Jar jar = null;
-        try {
-            jar = tldResourcePath.openJar();
+        try (Jar jar = tldResourcePath.openJar()) {
 
-        // Add the dependencies on the TLD to the referencing page
-        PageInfo pageInfo = ctxt.createCompiler().getPageInfo();
-        if (pageInfo != null) {
-            // If the TLD is in a JAR, that JAR may not be part of the web
-            // application
-            String path = tldResourcePath.getWebappPath();
-            if (path != null) {
-                // Add TLD (jar==null) / JAR (jar!=null) file to dependency 
list
-                pageInfo.addDependant(path, ctxt.getLastModified(path));
-            }
-            if (jar != null) {
-                if (path == null) {
-                    // JAR not in the web application so add it directly
-                    URL jarUrl = jar.getJarFileURL();
-                    long lastMod = -1;
-                    URLConnection urlConn = null;
+            // Add the dependencies on the TLD to the referencing page
+            PageInfo pageInfo = ctxt.createCompiler().getPageInfo();
+            if (pageInfo != null) {
+                // If the TLD is in a JAR, that JAR may not be part of the web
+                // application
+                String path = tldResourcePath.getWebappPath();
+                if (path != null) {
+                    // Add TLD (jar==null) / JAR (jar!=null) file to 
dependency list
+                    pageInfo.addDependant(path, ctxt.getLastModified(path));
+                }
+                if (jar != null) {
+                    if (path == null) {
+                        // JAR not in the web application so add it directly
+                        URL jarUrl = jar.getJarFileURL();
+                        long lastMod = -1;
+                        URLConnection urlConn = null;
+                        try {
+                            urlConn = jarUrl.openConnection();
+                            lastMod = urlConn.getLastModified();
+                        } catch (IOException ioe) {
+                            throw new JasperException(ioe);
+                        } finally {
+                            if (urlConn != null) {
+                                try {
+                                    urlConn.getInputStream().close();
+                                } catch (IOException e) {
+                                    // Ignore
+                                }
+                            }
+                        }
+                        pageInfo.addDependant(jarUrl.toExternalForm(),
+                                Long.valueOf(lastMod));
+                    }
+                    // Add TLD within the JAR to the dependency list
+                    String entryName = tldResourcePath.getEntryName();
                     try {
-                        urlConn = jarUrl.openConnection();
-                        lastMod = urlConn.getLastModified();
+                        pageInfo.addDependant(jar.getURL(entryName),
+                                Long.valueOf(jar.getLastModified(entryName)));
                     } catch (IOException ioe) {
                         throw new JasperException(ioe);
-                    } finally {
-                        if (urlConn != null) {
-                            try {
-                                urlConn.getInputStream().close();
-                            } catch (IOException e) {
-                                // Ignore
-                            }
-                        }
                     }
-                    pageInfo.addDependant(jarUrl.toExternalForm(),
-                            Long.valueOf(lastMod));
-                }
-                // Add TLD within the JAR to the dependency list
-                String entryName = tldResourcePath.getEntryName();
-                try {
-                    pageInfo.addDependant(jar.getURL(entryName),
-                            Long.valueOf(jar.getLastModified(entryName)));
-                } catch (IOException ioe) {
-                    throw new JasperException(ioe);
                 }
             }
-        }
 
-        // Get the representation of the TLD
-        TaglibXml taglibXml =
-                ctxt.getOptions().getTldCache().getTaglibXml(tldResourcePath);
-
-        // Populate the TagLibraryInfo attributes
-        this.jspversion = taglibXml.getJspVersion();
-        this.tlibversion = taglibXml.getTlibVersion();
-        this.shortname = taglibXml.getShortName();
-        this.urn = taglibXml.getUri();
-        this.info = taglibXml.getInfo();
-
-        this.tagLibraryValidator = createValidator(taglibXml.getValidator());
-
-        List<TagInfo> tagInfos = new ArrayList<>();
-        for (TagXml tagXml : taglibXml.getTags()) {
-            tagInfos.add(createTagInfo(tagXml));
-        }
-
-        List<TagFileInfo> tagFileInfos = new ArrayList<>();
-        for (TagFileXml tagFileXml : taglibXml.getTagFiles()) {
-            tagFileInfos.add(createTagFileInfo(tagFileXml, jar));
-        }
-
-        Set<String> names = new HashSet<>();
-        List<FunctionInfo> functionInfos = taglibXml.getFunctions();
-        // TODO Move this validation to the parsing stage
-        for (FunctionInfo functionInfo : functionInfos) {
-            String name = functionInfo.getName();
-            if (!names.add(name)) {
-                err.jspError("jsp.error.tld.fn.duplicate.name", name, uri);
+            // Get the representation of the TLD
+            TaglibXml taglibXml =
+                    
ctxt.getOptions().getTldCache().getTaglibXml(tldResourcePath);
+
+            // Populate the TagLibraryInfo attributes
+            this.jspversion = taglibXml.getJspVersion();
+            this.tlibversion = taglibXml.getTlibVersion();
+            this.shortname = taglibXml.getShortName();
+            this.urn = taglibXml.getUri();
+            this.info = taglibXml.getInfo();
+
+            this.tagLibraryValidator = 
createValidator(taglibXml.getValidator());
+
+            List<TagInfo> tagInfos = new ArrayList<>();
+            for (TagXml tagXml : taglibXml.getTags()) {
+                tagInfos.add(createTagInfo(tagXml));
             }
-        }
 
-        if (tlibversion == null) {
-            err.jspError("jsp.error.tld.mandatory.element.missing", 
"tlib-version", uri);
-        }
-        if (jspversion == null) {
-            err.jspError("jsp.error.tld.mandatory.element.missing", 
"jsp-version", uri);
-        }
+            List<TagFileInfo> tagFileInfos = new ArrayList<>();
+            for (TagFileXml tagFileXml : taglibXml.getTagFiles()) {
+                tagFileInfos.add(createTagFileInfo(tagFileXml, jar));
+            }
+
+            Set<String> names = new HashSet<>();
+            List<FunctionInfo> functionInfos = taglibXml.getFunctions();
+            // TODO Move this validation to the parsing stage
+            for (FunctionInfo functionInfo : functionInfos) {
+                String name = functionInfo.getName();
+                if (!names.add(name)) {
+                    err.jspError("jsp.error.tld.fn.duplicate.name", name, uri);
+                }
+            }
 
-        this.tags = tagInfos.toArray(new TagInfo[tagInfos.size()]);
-        this.tagFiles = tagFileInfos.toArray(new 
TagFileInfo[tagFileInfos.size()]);
-        this.functions = functionInfos.toArray(new 
FunctionInfo[functionInfos.size()]);
+            if (tlibversion == null) {
+                err.jspError("jsp.error.tld.mandatory.element.missing", 
"tlib-version", uri);
+            }
+            if (jspversion == null) {
+                err.jspError("jsp.error.tld.mandatory.element.missing", 
"jsp-version", uri);
+            }
+
+            this.tags = tagInfos.toArray(new TagInfo[tagInfos.size()]);
+            this.tagFiles = tagFileInfos.toArray(new 
TagFileInfo[tagFileInfos.size()]);
+            this.functions = functionInfos.toArray(new 
FunctionInfo[functionInfos.size()]);
         } catch (IOException ioe) {
             throw new JasperException(ioe);
         }
-        finally
-        {
-            if(null != jar)
-                jar.close(); // Jar.close does not throw IOException, but 
probably should
-        }
     }
 
     @Override



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

Reply via email to