From: <rb...@us...> - 2018-01-04 20:05:04
|
Revision: 15058 http://sourceforge.net/p/htmlunit/code/15058 Author: rbri Date: 2018-01-04 20:05:01 +0000 (Thu, 04 Jan 2018) Log Message: ----------- improve code based on spotbugs suggestions Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NotYetImplementedTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebServerTestCase.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTestsTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage4Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/JQueryExtractor.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/SVN.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -100,7 +100,6 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpProcessorBuilder; -import org.apache.http.protocol.HttpRequestExecutor; import org.apache.http.protocol.RequestContent; import org.apache.http.protocol.RequestTargetHost; import org.apache.http.ssl.SSLContexts; @@ -1007,11 +1006,6 @@ publicSuffixMatcher = PublicSuffixMatcherLoader.getDefault(); } - HttpRequestExecutor requestExec = getField(builder, "requestExec"); - if (requestExec == null) { - requestExec = new HttpRequestExecutor(); - } - LayeredConnectionSocketFactory sslSocketFactory = getField(builder, "sslSocketFactory"); final SocketConfig defaultSocketConfig = getField(builder, "defaultSocketConfig"); final ConnectionConfig defaultConnectionConfig = getField(builder, "defaultConnectionConfig"); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -383,7 +383,7 @@ final Attr result = super.setAttributeNode(attribute); - if ("src".equals(qualifiedName) && WebClient.ABOUT_BLANK != attributeValue) { + if ("src".equals(qualifiedName) && !WebClient.ABOUT_BLANK.equals(attributeValue)) { if (isAttachedToPage()) { loadSrc(); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.Arrays; import java.util.Locale; import java.util.Map; @@ -288,7 +289,7 @@ } } catch (final NumberFormatException e) { - LOG.warn("Invalid rect coords '" + coords + "'", e); + LOG.warn("Invalid rect coords '" + Arrays.toString(coords) + "'", e); } final Rectangle2D rectangle = new Rectangle2D.Double(leftX, topY, @@ -332,7 +333,7 @@ } } catch (final NumberFormatException e) { - LOG.warn("Invalid poly coords '" + coords + "'", e); + LOG.warn("Invalid poly coords '" + Arrays.toString(coords) + "'", e); } path.closePath(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -3141,7 +3141,6 @@ || valueString.endsWith("mm") || valueString.endsWith("in") || valueString.endsWith("pc") - || valueString.endsWith("pc") || valueString.endsWith("ch") || valueString.endsWith("vh") || valueString.endsWith("vw")) { Modified: trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java =================================================================== --- trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/main/java/netscape/javascript/JSObject.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -15,6 +15,7 @@ package netscape.javascript; import java.applet.Applet; +import java.util.Arrays; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,7 +63,7 @@ */ public Object call(final String methodName, final Object[] args) throws JSException { if (LOG.isInfoEnabled()) { - LOG.info("JSObject call '" + methodName + "(" + args + ")'"); + LOG.info("JSObject call '" + methodName + "(" + Arrays.toString(args) + ")'"); } final Object jsResult = ScriptableObject.callMethod(scriptableObject_, methodName, args); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -142,17 +142,20 @@ } private void unusedCheck(final File dir, final List<String> unusedFeatures) throws IOException { - for (final File file : dir.listFiles()) { - if (file.isDirectory() && !".svn".equals(file.getName())) { - unusedCheck(file, unusedFeatures); - } - else if (file.getName().endsWith(".java")) { - final List<String> lines = FileUtils.readLines(file, ISO_8859_1); - final String browserVersionFeatures = BrowserVersionFeatures.class.getSimpleName(); - for (final String line : lines) { - for (final Iterator<String> it = unusedFeatures.iterator(); it.hasNext();) { - if (line.contains(browserVersionFeatures + '.' + it.next())) { - it.remove(); + final File[] files = dir.listFiles(); + if (files != null) { + for (final File file : files) { + if (file.isDirectory() && !".svn".equals(file.getName())) { + unusedCheck(file, unusedFeatures); + } + else if (file.getName().endsWith(".java")) { + final List<String> lines = FileUtils.readLines(file, ISO_8859_1); + final String browserVersionFeatures = BrowserVersionFeatures.class.getSimpleName(); + for (final String line : lines) { + for (final Iterator<String> it = unusedFeatures.iterator(); it.hasNext();) { + if (line.contains(browserVersionFeatures + '.' + it.next())) { + it.remove(); + } } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -982,7 +982,12 @@ } private void testTests(final File dir) throws Exception { - for (final File file : dir.listFiles()) { + final File[] files = dir.listFiles(); + if (files == null) { + return; + } + + for (final File file : files) { if (file.isDirectory()) { if (!".svn".equals(file.getName())) { testTests(file); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -48,7 +48,7 @@ public class ExternalTest { /** Chrome driver. */ - static String CHROME_DRIVER_ = "2.34"; + static String CHROME_DRIVER_ = "2.33"; private static final DateFormat TEAM_CITY_FORMAT_ = new SimpleDateFormat("dd MMM yy HH:mm", Locale.ROOT); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NotYetImplementedTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NotYetImplementedTest.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/NotYetImplementedTest.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -47,23 +47,26 @@ } private void process(final File dir) throws IOException { - for (final File file : dir.listFiles()) { - final String fileName = file.getName(); - if (file.isDirectory() - && !"huge".equals(fileName) - && !".svn".equals(fileName)) { - process(file); - } - else { - if (fileName.endsWith(".java") - && !"SimpleWebTestCase.java".equals(fileName) - && !"NotYetImplementedTest.java".equals(fileName) - && !"CodeStyleTest.java".equals(fileName)) { - final List<String> lines = FileUtils.readLines(file, ISO_8859_1); - final String relativePath = file.getAbsolutePath().substring( - new File(".").getAbsolutePath().length() - 1).replace('\\', '/'); - process(lines, relativePath); + final File[] files = dir.listFiles(); + if (files != null) { + for (final File file : files) { + final String fileName = file.getName(); + if (file.isDirectory() + && !"huge".equals(fileName) + && !".svn".equals(fileName)) { + process(file); } + else { + if (fileName.endsWith(".java") + && !"SimpleWebTestCase.java".equals(fileName) + && !"NotYetImplementedTest.java".equals(fileName) + && !"CodeStyleTest.java".equals(fileName)) { + final List<String> lines = FileUtils.readLines(file, ISO_8859_1); + final String relativePath = file.getAbsolutePath().substring( + new File(".").getAbsolutePath().length() - 1).replace('\\', '/'); + process(lines, relativePath); + } + } } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -494,7 +494,7 @@ } LAST_TEST_MockWebConnection_ = Boolean.TRUE; if (STATIC_SERVER_ == null) { - STATIC_SERVER_ = new Server(PORT); + final Server server = new Server(PORT); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); @@ -521,27 +521,30 @@ context.addFilter(AsciiEncodingFilter.class, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST)); } - STATIC_SERVER_.setHandler(context); - STATIC_SERVER_.start(); + server.setHandler(context); + server.start(); + STATIC_SERVER_ = server; } MockWebConnectionServlet.MockConnection_ = mockConnection; if (STATIC_SERVER2_ == null && needThreeConnections()) { - STATIC_SERVER2_ = new Server(PORT2); + Server server = new Server(PORT2); final WebAppContext context2 = new WebAppContext(); context2.setContextPath("/"); context2.setResourceBase("./"); context2.addServlet(MockWebConnectionServlet.class, "/*"); - STATIC_SERVER2_.setHandler(context2); - STATIC_SERVER2_.start(); + server.setHandler(context2); + server.start(); + STATIC_SERVER2_ = server; - STATIC_SERVER3_ = new Server(PORT3); + server = new Server(PORT3); final WebAppContext context3 = new WebAppContext(); context3.setContextPath("/"); context3.setResourceBase("./"); context3.addServlet(MockWebConnectionServlet.class, "/*"); - STATIC_SERVER3_.setHandler(context3); - STATIC_SERVER3_.start(); + server.setHandler(context3); + server.start(); + STATIC_SERVER3_ = server; /* * The mock connection servlet call sit under both servers, so long as tests * keep the URLs distinct. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebServerTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebServerTestCase.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebServerTestCase.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -319,7 +319,7 @@ } LAST_TEST_MockWebConnection_ = Boolean.TRUE; if (STATIC_SERVER_ == null) { - STATIC_SERVER_ = new Server(PORT); + final Server server = new Server(PORT); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); @@ -341,8 +341,9 @@ } context.addServlet(MockWebConnectionServlet.class, "/*"); - STATIC_SERVER_.setHandler(context); - STATIC_SERVER_.start(); + server.setHandler(context); + server.start(); + STATIC_SERVER_ = server; } MockWebConnectionServlet.setMockconnection(mockConnection); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTestsTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTestsTest.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTestsTest.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -72,16 +72,19 @@ } private void collectionObjectNames(final File dir, final Set<String> set) throws IOException { - for (final File file : dir.listFiles()) { - if (file.isDirectory() && !".svn".equals(file.getName())) { - collectionObjectNames(file, set); - } - else if (file.getName().endsWith(".java")) { - final List<String> lines = FileUtils.readLines(file, ISO_8859_1); - for (final String line : lines) { - final Matcher matcher = pattern_.matcher(line); - while (matcher.find()) { - set.add(matcher.group(1)); + final File[] files = dir.listFiles(); + if (files != null) { + for (final File file : files) { + if (file.isDirectory() && !".svn".equals(file.getName())) { + collectionObjectNames(file, set); + } + else if (file.getName().endsWith(".java")) { + final List<String> lines = FileUtils.readLines(file, ISO_8859_1); + for (final String line : lines) { + final Matcher matcher = pattern_.matcher(line); + while (matcher.find()) { + set.add(matcher.group(1)); + } } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage4Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage4Test.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage4Test.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -202,6 +202,9 @@ return name.startsWith("htmlunit"); } }); + if (list == null) { + return 0; + } return list.length; } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/JQueryExtractor.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/JQueryExtractor.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/JQueryExtractor.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -157,12 +157,15 @@ } } final Map<String, Expectations> browserExpectations = new HashMap<>(); - for (final File file : dir.listFiles()) { - if (file.isFile() && file.getName().endsWith(".txt")) { - for (final TestedBrowser b : browsers) { - final String browserName = b.name(); - if (file.getName().equalsIgnoreCase("results." + browserName.replace('_', '.') + ".txt")) { - browserExpectations.put(browserName, Expectations.readExpectations(file)); + final File[] files = dir.listFiles(); + if (files != null) { + for (final File file : files) { + if (file.isFile() && file.getName().endsWith(".txt")) { + for (final TestedBrowser b : browsers) { + final String browserName = b.name(); + if (file.getName().equalsIgnoreCase("results." + browserName.replace('_', '.') + ".txt")) { + browserExpectations.put(browserName, Expectations.readExpectations(file)); + } } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/SVN.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/SVN.java 2018-01-02 19:14:46 UTC (rev 15057) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/source/SVN.java 2018-01-04 20:05:01 UTC (rev 15058) @@ -54,14 +54,17 @@ * @throws IOException if an exception happens */ public static void deleteSVN(final File dir) throws IOException { - for (final File f : dir.listFiles()) { - if (f.isDirectory()) { - if (".svn".equals(f.getName())) { - FileUtils.deleteDirectory(f); + final File[] files = dir.listFiles(); + if (files != null) { + for (final File f : files) { + if (f.isDirectory()) { + if (".svn".equals(f.getName())) { + FileUtils.deleteDirectory(f); + } + else { + deleteSVN(f); + } } - else { - deleteSVN(f); - } } } } @@ -72,18 +75,21 @@ * @throws IOException if an exception happens */ public static void consistentNewlines(final File dir) throws IOException { - for (final File f : dir.listFiles()) { - if (f.isDirectory()) { - if (!".svn".equals(f.getName())) { - consistentNewlines(f); + final File[] files = dir.listFiles(); + if (files != null) { + for (final File f : files) { + if (f.isDirectory()) { + if (!".svn".equals(f.getName())) { + consistentNewlines(f); + } } - } - else { - final String fileName = f.getName().toLowerCase(Locale.ROOT); - for (final String extension : EOL_EXTENSIONS_) { - if (fileName.endsWith(extension)) { - FileUtils.writeLines(f, FileUtils.readLines(f, ISO_8859_1)); - break; + else { + final String fileName = f.getName().toLowerCase(Locale.ROOT); + for (final String extension : EOL_EXTENSIONS_) { + if (fileName.endsWith(extension)) { + FileUtils.writeLines(f, FileUtils.readLines(f, ISO_8859_1)); + break; + } } } } |