diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index e13fb06056..e4575086d9 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -1783,8 +1783,6 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas public void copy(File target) throws Exception { try (InputStream input = ProxyConfiguration.getInputStream(new URL(url))) { Files.copy(input, target.toPath()); - } catch (Exception e) { - throw e; } } diff --git a/core/src/main/java/hudson/tasks/Shell.java b/core/src/main/java/hudson/tasks/Shell.java index 01dbed51c5..4e6395d870 100644 --- a/core/src/main/java/hudson/tasks/Shell.java +++ b/core/src/main/java/hudson/tasks/Shell.java @@ -27,6 +27,7 @@ package hudson.tasks; import edu.umd.cs.findbugs.annotations.CheckForNull; import hudson.Extension; import hudson.FilePath; +import hudson.Functions; import hudson.Util; import hudson.model.AbstractProject; import hudson.model.PersistentDescriptor; @@ -43,7 +44,6 @@ import jenkins.security.MasterToSlaveCallable; import jenkins.tasks.filters.EnvVarsFilterLocalRule; import jenkins.tasks.filters.EnvVarsFilterLocalRuleDescriptor; import net.sf.json.JSONObject; -import org.apache.commons.lang.SystemUtils; import org.jenkinsci.Symbol; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.Beta; @@ -175,7 +175,7 @@ public class Shell extends CommandInterpreter { @Deprecated public String getShellOrDefault() { if (shell == null) { - return SystemUtils.IS_OS_WINDOWS ? "sh" : "/bin/sh"; + return Functions.isWindows() ? "sh" : "/bin/sh"; } return shell; } @@ -251,7 +251,7 @@ public class Shell extends CommandInterpreter { @Override public String call() throws IOException { - return SystemUtils.IS_OS_WINDOWS ? "sh" : "/bin/sh"; + return Functions.isWindows() ? "sh" : "/bin/sh"; } } diff --git a/core/src/main/java/hudson/util/PackedMap.java b/core/src/main/java/hudson/util/PackedMap.java index 5e871e24ea..f070c368d6 100644 --- a/core/src/main/java/hudson/util/PackedMap.java +++ b/core/src/main/java/hudson/util/PackedMap.java @@ -28,6 +28,7 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.converters.collections.MapConverter; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.mapper.Mapper; +import edu.umd.cs.findbugs.annotations.NonNull; import java.util.AbstractList; import java.util.AbstractMap; import java.util.AbstractSet; @@ -54,9 +55,8 @@ import java.util.TreeMap; * * @author Kohsuke Kawaguchi */ -@SuppressWarnings("unchecked") public final class PackedMap extends AbstractMap { - private Object[] kvpairs; + private final Object[] kvpairs; /** * @@ -77,6 +77,7 @@ public final class PackedMap extends AbstractMap { } private final Set> entrySet = new AbstractSet>() { + @NonNull @Override public Iterator> iterator() { return new Iterator>() { @@ -136,6 +137,7 @@ public final class PackedMap extends AbstractMap { } @Override + @SuppressWarnings("unchecked") public V get(Object key) { for (int i = 0; i < kvpairs.length; i += 2) if (key.equals(kvpairs[i])) @@ -143,7 +145,9 @@ public final class PackedMap extends AbstractMap { return null; } + @NonNull @Override + @SuppressWarnings("unchecked") public Collection values() { return new AbstractList() { @Override @@ -178,7 +182,7 @@ public final class PackedMap extends AbstractMap { @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { - return PackedMap.of((Map) super.unmarshal(reader, context)); + return PackedMap.of((Map) super.unmarshal(reader, context)); } } } diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index c4471f34a0..a15f6edc0c 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -2256,7 +2256,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve */ void trimLabels(Node... nodes) { Set includedLabels = new HashSet<>(); - Arrays.asList(nodes).stream().filter(Objects::nonNull).forEach(n -> includedLabels.addAll(n.getAssignedLabels())); + Arrays.stream(nodes).filter(Objects::nonNull).forEach(n -> includedLabels.addAll(n.getAssignedLabels())); trimLabels(includedLabels); } diff --git a/core/src/main/java/jenkins/model/lazy/LazyLoadRunMapEntrySet.java b/core/src/main/java/jenkins/model/lazy/LazyLoadRunMapEntrySet.java index 00fa1d68bf..c0ca184422 100644 --- a/core/src/main/java/jenkins/model/lazy/LazyLoadRunMapEntrySet.java +++ b/core/src/main/java/jenkins/model/lazy/LazyLoadRunMapEntrySet.java @@ -50,7 +50,7 @@ class LazyLoadRunMapEntrySet extends AbstractSet> { @Override public boolean contains(Object o) { if (o instanceof Map.Entry) { - Map.Entry e = (Map.Entry) o; + Map.Entry e = (Map.Entry) o; Object k = e.getKey(); if (k instanceof Integer) { return owner.getByNumber((Integer) k).equals(e.getValue()); diff --git a/core/src/test/java/hudson/ChannelRule.java b/core/src/test/java/hudson/ChannelRule.java index 02f64dc54b..2de863675c 100644 --- a/core/src/test/java/hudson/ChannelRule.java +++ b/core/src/test/java/hudson/ChannelRule.java @@ -6,6 +6,7 @@ import hudson.remoting.ChannelBuilder; import hudson.remoting.FastPipedInputStream; import hudson.remoting.FastPipedOutputStream; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -54,50 +55,7 @@ public final class ChannelRule extends ExternalResource { french.join(); british.join(); } catch (IOException e) { - // perhaps this exception is caused by earlier abnormal termination of the channel? - /* for the record, this is the failure. - Nov 12, 2009 6:18:55 PM hudson.remoting.Channel$CloseCommand execute - SEVERE: close command failed on This side of the channel - java.io.IOException: Pipe is already closed - at hudson.remoting.FastPipedOutputStream.write(FastPipedOutputStream.java:127) - at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1838) - at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1747) - at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1249) - at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1203) - at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1387) - at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150) - at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1538) - at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:329) - at hudson.remoting.Channel.send(Channel.java:413) - at hudson.remoting.Channel.close(Channel.java:717) - at hudson.remoting.Channel$CloseCommand.execute(Channel.java:676) - at hudson.remoting.Channel$ReaderThread.run(Channel.java:860) - Caused by: hudson.remoting.FastPipedInputStream$ClosedBy: The pipe was closed at... - at hudson.remoting.FastPipedInputStream.close(FastPipedInputStream.java:103) - at java.io.ObjectInputStream$PeekInputStream.close(ObjectInputStream.java:2305) - at java.io.ObjectInputStream$BlockDataInputStream.close(ObjectInputStream.java:2643) - at java.io.ObjectInputStream.close(ObjectInputStream.java:873) - at hudson.remoting.Channel$ReaderThread.run(Channel.java:866) - Nov 12, 2009 6:18:55 PM hudson.remoting.Channel$CloseCommand execute - INFO: close command created at - Command close created at - at hudson.remoting.Command.(Command.java:58) - at hudson.remoting.Command.(Command.java:47) - at hudson.remoting.Channel$CloseCommand.(Channel.java:673) - at hudson.remoting.Channel$CloseCommand.(Channel.java:673) - at hudson.remoting.Channel.close(Channel.java:717) - at hudson.remoting.Channel$CloseCommand.execute(Channel.java:676) - at hudson.remoting.Channel$ReaderThread.run(Channel.java:860) - Nov 12, 2009 6:18:55 PM hudson.remoting.Channel$ReaderThread run - SEVERE: I/O error in channel This side of the channel - java.io.EOFException - at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2554) - at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297) - at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) - at hudson.remoting.Channel$ReaderThread.run(Channel.java:849) - - */ - e.printStackTrace(); + throw new UncheckedIOException(e); } catch (InterruptedException x) { throw new AssertionError(x); } diff --git a/core/src/test/java/hudson/util/ConsistentHashTest.java b/core/src/test/java/hudson/util/ConsistentHashTest.java index f1030a0913..c2f968810c 100644 --- a/core/src/test/java/hudson/util/ConsistentHashTest.java +++ b/core/src/test/java/hudson/util/ConsistentHashTest.java @@ -170,10 +170,8 @@ public class ConsistentHashTest { throw exception; }; - final RuntimeException e = assertThrows(RuntimeException.class, () -> { - ConsistentHash hash = new ConsistentHash<>(hashFunction); - hash.add("foo"); - }); + ConsistentHash hash = new ConsistentHash<>(hashFunction); + final RuntimeException e = assertThrows(RuntimeException.class, () -> hash.add("foo")); assertSame(exception, e); } diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java b/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java index 07fc75d982..3e1631692c 100644 --- a/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java +++ b/core/src/test/java/jenkins/org/apache/commons/validator/routines/DomainValidatorTest.java @@ -393,7 +393,7 @@ public class DomainValidatorTest extends TestCase { } br.close(); // List html entries not in TLD text list - for (String key : (new TreeMap<>(htmlInfo)).keySet()) { + for (String key : new TreeMap<>(htmlInfo).keySet()) { if (!ianaTlds.contains(key)) { if (isNotInRootZone(key)) { System.out.println("INFO: HTML entry not yet in root zone: " + key); diff --git a/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java b/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java index 9320e16349..97cb3f7c54 100644 --- a/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java +++ b/core/src/test/java/jenkins/org/apache/commons/validator/routines/UrlValidatorTest.java @@ -401,7 +401,7 @@ public class UrlValidatorTest { } - return (!maxIndex); + return !maxIndex; } private String testPartsIndextoString() { diff --git a/test/src/test/java/hudson/model/QueueTest.java b/test/src/test/java/hudson/model/QueueTest.java index 6d0c0cbfff..f49b4dd30c 100644 --- a/test/src/test/java/hudson/model/QueueTest.java +++ b/test/src/test/java/hudson/model/QueueTest.java @@ -338,7 +338,7 @@ public class QueueTest { @SuppressWarnings("deprecation") HtmlPage p = (HtmlPage) wc.getPage("http://localhost:" + connector.getLocalPort() + '/'); HtmlForm f = p.getFormByName("main"); - HtmlFileInput input = (HtmlFileInput) f.getInputByName("test"); + HtmlFileInput input = f.getInputByName("test"); input.setData(testData); HtmlFormUtil.submit(f); } finally { diff --git a/test/src/test/java/hudson/model/ViewTest.java b/test/src/test/java/hudson/model/ViewTest.java index 6abbdec608..b2723d5422 100644 --- a/test/src/test/java/hudson/model/ViewTest.java +++ b/test/src/test/java/hudson/model/ViewTest.java @@ -55,7 +55,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlLabel; import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.gargoylesoftware.htmlunit.util.NameValuePair; import edu.umd.cs.findbugs.annotations.CheckForNull; @@ -175,9 +174,9 @@ public class ViewTest { HtmlAnchor privateViewsLink = userPage.getAnchorByText("My Views"); assertNotNull("My Views link not available", privateViewsLink); - HtmlPage privateViewsPage = (HtmlPage) privateViewsLink.click(); + HtmlPage privateViewsPage = privateViewsLink.click(); - Text viewLabel = (Text) privateViewsPage.getFirstByXPath("//div[@class='tabBar']//div[@class='tab active']/a/text()"); + Text viewLabel = privateViewsPage.getFirstByXPath("//div[@class='tabBar']//div[@class='tab active']/a/text()"); assertTrue("'All' view should be selected", viewLabel.getTextContent().contains(Hudson_ViewName())); View listView = listView("listView"); @@ -185,7 +184,7 @@ public class ViewTest { HtmlPage newViewPage = wc.goTo("user/me/my-views/newView"); HtmlForm form = newViewPage.getFormByName("createItem"); form.getInputByName("name").setValueAttribute("proxy-view"); - ((HtmlRadioButtonInput) form.getInputByValue("hudson.model.ProxyView")).setChecked(true); + form.getInputByValue("hudson.model.ProxyView").setChecked(true); HtmlPage proxyViewConfigurePage = j.submit(form); View proxyView = user.getProperty(MyViewsProperty.class).getView("proxy-view"); assertNotNull(proxyView); diff --git a/test/src/test/java/hudson/security/LoginTest.java b/test/src/test/java/hudson/security/LoginTest.java index 4796370757..c6d59a672e 100644 --- a/test/src/test/java/hudson/security/LoginTest.java +++ b/test/src/test/java/hudson/security/LoginTest.java @@ -7,7 +7,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlFormUtil; import com.gargoylesoftware.htmlunit.html.HtmlPage; @@ -86,7 +85,7 @@ public class LoginTest { HtmlForm form = page.getFormByName("login"); form.getInputByName("j_username").setValueAttribute("alice"); form.getInputByName("j_password").setValueAttribute("alice"); - ((HtmlCheckBoxInput) form.getInputByName("remember_me")).setChecked(true); + form.getInputByName("remember_me").setChecked(true); return form; } diff --git a/test/src/test/java/lib/form/RowVisibilityGroupTest.java b/test/src/test/java/lib/form/RowVisibilityGroupTest.java index 5cf662deda..6d3882d237 100644 --- a/test/src/test/java/lib/form/RowVisibilityGroupTest.java +++ b/test/src/test/java/lib/form/RowVisibilityGroupTest.java @@ -54,9 +54,9 @@ public class RowVisibilityGroupTest { public void test1() throws Exception { HtmlPage p = j.createWebClient().goTo("self/test1"); - HtmlElement outer = (HtmlElement) DomNodeUtil.selectSingleNode(p, "//INPUT[@name='outer']"); - HtmlElement inner = (HtmlElement) DomNodeUtil.selectSingleNode(p, "//INPUT[@name='inner']"); - HtmlInput field = (HtmlInput) DomNodeUtil.selectSingleNode(p, "//INPUT[@type='text'][@name='_.field']"); + HtmlElement outer = DomNodeUtil.selectSingleNode(p, "//INPUT[@name='outer']"); + HtmlElement inner = DomNodeUtil.selectSingleNode(p, "//INPUT[@name='inner']"); + HtmlInput field = DomNodeUtil.selectSingleNode(p, "//INPUT[@type='text'][@name='_.field']"); // outer gets unfolded, but inner should be still folded outer.click(); @@ -80,7 +80,7 @@ public class RowVisibilityGroupTest { public void test2() throws Exception { HtmlPage p = j.createWebClient().goTo("self/test2"); - HtmlSelect s = (HtmlSelect) DomNodeUtil.selectSingleNode(p, "//SELECT"); + HtmlSelect s = DomNodeUtil.selectSingleNode(p, "//SELECT"); List opts = s.getOptions(); // those first selections will load additional HTMLs diff --git a/test/src/test/java/lib/layout/RenderOnDemandTest.java b/test/src/test/java/lib/layout/RenderOnDemandTest.java index e4a3ca6835..757394a4e4 100644 --- a/test/src/test/java/lib/layout/RenderOnDemandTest.java +++ b/test/src/test/java/lib/layout/RenderOnDemandTest.java @@ -30,7 +30,6 @@ import static org.junit.Assert.assertNull; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.WebClientUtil; -import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.model.InvisibleAction; import hudson.model.RootAction; @@ -95,7 +94,7 @@ public class RenderOnDemandTest { HtmlPage p = j.createWebClient().goTo("self/testScript"); assertNull(p.getElementById("loaded")); - ((HtmlElement) p.getElementById("button")).click(); + p.getElementById("button").click(); WebClientUtil.waitForJSExec(p.getWebClient()); // all AJAX calls complete before the above method returns assertNotNull(p.getElementById("loaded"));