From bdefea2b99d9c8be3e1884333e498cf7c115c039 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 8 Apr 2009 15:25:05 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46986 Find bugs was complaining although these have not been reported as causing issues for any users. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@763281 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/Constants.java | 19 ++++++++++++++++--- java/org/apache/jasper/compiler/PageInfo.java | 3 +-- java/org/apache/jasper/xmlparser/ParserUtils.java | 7 ++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/java/org/apache/jasper/Constants.java b/java/org/apache/jasper/Constants.java index 66de25db3..90db0035f 100644 --- a/java/org/apache/jasper/Constants.java +++ b/java/org/apache/jasper/Constants.java @@ -17,6 +17,10 @@ package org.apache.jasper; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + /** * Some constants and other global data that are used by the compiler and the runtime. @@ -51,11 +55,13 @@ public class Constants { * These classes/packages are automatically imported by the * generated code. */ - public static final String[] STANDARD_IMPORTS = { + private static final String[] PRIVATE_STANDARD_IMPORTS = { "javax.servlet.*", "javax.servlet.http.*", "javax.servlet.jsp.*" }; + public static final List STANDARD_IMPORTS = + Collections.unmodifiableList(Arrays.asList(PRIVATE_STANDARD_IMPORTS)); /** * ServletContext attribute for classpath. This is tomcat specific. @@ -152,18 +158,25 @@ public class Constants { * an EntityResolver to return the location of the * cached copy of a DTD. */ - public static final String[] CACHED_DTD_PUBLIC_IDS = { + // TODO Add 2.4, 2.5, 3.0 + private static final String[] PRIVATE_CACHED_DTD_PUBLIC_IDS = { TAGLIB_DTD_PUBLIC_ID_11, TAGLIB_DTD_PUBLIC_ID_12, WEBAPP_DTD_PUBLIC_ID_22, WEBAPP_DTD_PUBLIC_ID_23, }; - public static final String[] CACHED_DTD_RESOURCE_PATHS = { + public static final List CACHED_DTD_PUBLIC_IDS = + Collections.unmodifiableList( + Arrays.asList(PRIVATE_CACHED_DTD_PUBLIC_IDS)); + private static final String[] PRIVATE_CACHED_DTD_RESOURCE_PATHS = { TAGLIB_DTD_RESOURCE_PATH_11, TAGLIB_DTD_RESOURCE_PATH_12, WEBAPP_DTD_RESOURCE_PATH_22, WEBAPP_DTD_RESOURCE_PATH_23, }; + public static final List CACHED_DTD_RESOURCE_PATHS = + Collections.unmodifiableList( + Arrays.asList(PRIVATE_CACHED_DTD_RESOURCE_PATHS)); /** * Default URLs to download the pluging for Netscape and IE. diff --git a/java/org/apache/jasper/compiler/PageInfo.java b/java/org/apache/jasper/compiler/PageInfo.java index 70b30d726..84fba8a94 100644 --- a/java/org/apache/jasper/compiler/PageInfo.java +++ b/java/org/apache/jasper/compiler/PageInfo.java @@ -110,8 +110,7 @@ class PageInfo { this.prefixes = new HashSet(); // Enter standard imports - for(int i = 0; i < Constants.STANDARD_IMPORTS.length; i++) - imports.add(Constants.STANDARD_IMPORTS[i]); + imports.addAll(Constants.STANDARD_IMPORTS); } /** diff --git a/java/org/apache/jasper/xmlparser/ParserUtils.java b/java/org/apache/jasper/xmlparser/ParserUtils.java index 7f9a71fa0..661ae5a29 100644 --- a/java/org/apache/jasper/xmlparser/ParserUtils.java +++ b/java/org/apache/jasper/xmlparser/ParserUtils.java @@ -193,10 +193,11 @@ class MyEntityResolver implements EntityResolver { public InputSource resolveEntity(String publicId, String systemId) throws SAXException { - for (int i = 0; i < Constants.CACHED_DTD_PUBLIC_IDS.length; i++) { - String cachedDtdPublicId = Constants.CACHED_DTD_PUBLIC_IDS[i]; + for (int i = 0; i < Constants.CACHED_DTD_PUBLIC_IDS.size(); i++) { + String cachedDtdPublicId = Constants.CACHED_DTD_PUBLIC_IDS.get(i); if (cachedDtdPublicId.equals(publicId)) { - String resourcePath = Constants.CACHED_DTD_RESOURCE_PATHS[i]; + String resourcePath = + Constants.CACHED_DTD_RESOURCE_PATHS.get(i); InputStream input = this.getClass().getResourceAsStream( resourcePath); if (input == null) { -- 2.11.0