diff --git a/cli/pom.xml b/cli/pom.xml
index 3741777f4d92cbdcf1df394ffc382462d7b67fc9..e1876fcf11548bc82dbdbbfcd78c52b1335c1814 100644
--- a/cli/pom.xml
+++ b/cli/pom.xml
@@ -5,7 +5,7 @@
org.jenkins-ci.mainpom
- 2.56-SNAPSHOT
+ 2.57-SNAPSHOTcli
diff --git a/cli/src/main/java/hudson/cli/PrivateKeyProvider.java b/cli/src/main/java/hudson/cli/PrivateKeyProvider.java
index a1f6b3389030fe8e13a990cc5c0e3eabd5ad647f..d7753a750498aff78325fc04326eb63b7e45209d 100644
--- a/cli/src/main/java/hudson/cli/PrivateKeyProvider.java
+++ b/cli/src/main/java/hudson/cli/PrivateKeyProvider.java
@@ -32,6 +32,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.KeyPair;
@@ -134,6 +135,8 @@ public class PrivateKeyProvider {
byte[] bytes = new byte[(int) f.length()];
dis.readFully(bytes);
return new String(bytes);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
}
diff --git a/core/pom.xml b/core/pom.xml
index 6a44b41d4ca3337ebf0858609266667d990753b2..48731794d006e1b1c0ee5c7a76a38ed02b11d620 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -29,7 +29,7 @@ THE SOFTWARE.
org.jenkins-ci.mainpom
- 2.56-SNAPSHOT
+ 2.57-SNAPSHOTjenkins-core
diff --git a/core/src/main/java/hudson/ClassicPluginStrategy.java b/core/src/main/java/hudson/ClassicPluginStrategy.java
index 2744f537e66a267e0d8f536b8aeaee615e6fdd71..c64f331b9baa68d6db14f27b4088a4ac58f9d1ff 100644
--- a/core/src/main/java/hudson/ClassicPluginStrategy.java
+++ b/core/src/main/java/hudson/ClassicPluginStrategy.java
@@ -25,6 +25,7 @@ package hudson;
import java.io.InputStream;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import jenkins.util.SystemProperties;
import com.google.common.collect.Lists;
import hudson.Plugin.DummyImpl;
@@ -127,6 +128,8 @@ public class ClassicPluginStrategy implements PluginStrategy {
String firstLine;
try (InputStream manifestHeaderInput = Files.newInputStream(archive.toPath())) {
firstLine = IOUtils.readFirstLine(manifestHeaderInput, "UTF-8");
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
if (firstLine.startsWith("Manifest-Version:")) {
// this is the manifest already
@@ -138,6 +141,8 @@ public class ClassicPluginStrategy implements PluginStrategy {
// Read the manifest
try (InputStream manifestInput = Files.newInputStream(archive.toPath())) {
return new Manifest(manifestInput);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
} catch (IOException e) {
throw new IOException("Failed to load " + archive, e);
@@ -171,6 +176,8 @@ public class ClassicPluginStrategy implements PluginStrategy {
}
try (InputStream fin = Files.newInputStream(manifestFile.toPath())) {
manifest = new Manifest(fin);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
}
diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java
index 985bf56e33349231420d9bc2909651e2466cd317..3ba026d7971226f2be4cbf9e7dcd1289a5c5a535 100644
--- a/core/src/main/java/hudson/FilePath.java
+++ b/core/src/main/java/hudson/FilePath.java
@@ -78,6 +78,7 @@ import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -1469,8 +1470,13 @@ public final class FilePath implements Serializable {
act(new SecureFileCallable() {
private static final long serialVersionUID = -5094638816500738429L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
- if(!f.exists())
- Files.newOutputStream(creating(f).toPath()).close();
+ if(!f.exists()) {
+ try {
+ Files.newOutputStream(creating(f).toPath()).close();
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
+ }
+ }
if(!stating(f).setLastModified(timestamp))
throw new IOException("Failed to set the timestamp of "+f+" to "+timestamp);
return null;
@@ -1750,8 +1756,13 @@ public final class FilePath implements Serializable {
* Reads this file.
*/
public InputStream read() throws IOException, InterruptedException {
- if(channel==null)
- return Files.newInputStream(reading(new File(remote)).toPath());
+ if(channel==null) {
+ try {
+ return Files.newInputStream(reading(new File(remote)).toPath());
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
+ }
+ }
final Pipe p = Pipe.createRemoteToLocal();
actAsync(new SecureFileCallable() {
@@ -1762,6 +1773,8 @@ public final class FilePath implements Serializable {
try (InputStream fis = Files.newInputStream(reading(f).toPath());
OutputStream out = p.getOut()) {
org.apache.commons.io.IOUtils.copy(fis, out);
+ } catch (InvalidPathException e) {
+ p.error(new IOException(e));
} catch (Exception x) {
p.error(x);
}
@@ -1862,7 +1875,11 @@ public final class FilePath implements Serializable {
if(channel==null) {
File f = new File(remote).getAbsoluteFile();
mkdirs(f.getParentFile());
- return Files.newOutputStream(writing(f).toPath());
+ try {
+ return Files.newOutputStream(writing(f).toPath());
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
+ }
}
return act(new SecureFileCallable() {
@@ -1870,8 +1887,12 @@ public final class FilePath implements Serializable {
public OutputStream invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
f = f.getAbsoluteFile();
mkdirs(f.getParentFile());
- OutputStream fos = Files.newOutputStream(writing(f).toPath());
- return new RemoteOutputStream(fos);
+ try {
+ OutputStream fos = Files.newOutputStream(writing(f).toPath());
+ return new RemoteOutputStream(fos);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
+ }
}
});
}
@@ -1891,6 +1912,8 @@ public final class FilePath implements Serializable {
try (OutputStream fos = Files.newOutputStream(writing(f).toPath());
Writer w = encoding != null ? new OutputStreamWriter(fos, encoding) : new OutputStreamWriter(fos)) {
w.write(content);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
return null;
}
@@ -1994,6 +2017,8 @@ public final class FilePath implements Serializable {
try (InputStream fis = Files.newInputStream(reading(f).toPath())) {
org.apache.commons.io.IOUtils.copy(fis, out);
return null;
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
} finally {
out.close();
}
diff --git a/core/src/main/java/hudson/FileSystemProvisioner.java b/core/src/main/java/hudson/FileSystemProvisioner.java
index 5b13241fbe998303df80215d2309db56ed6b8565..13f55b7370028832eba66ea7e16af84cb19547aa 100644
--- a/core/src/main/java/hudson/FileSystemProvisioner.java
+++ b/core/src/main/java/hudson/FileSystemProvisioner.java
@@ -32,6 +32,7 @@ import hudson.model.Job;
import hudson.model.TaskListener;
import hudson.util.io.ArchiverFactory;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import jenkins.model.Jenkins;
import hudson.model.listeners.RunListener;
import hudson.scm.SCM;
@@ -218,6 +219,8 @@ public abstract class FileSystemProvisioner implements ExtensionPoint, Describab
File wss = new File(build.getRootDir(),"workspace.tgz");
try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(wss.toPath()))) {
ws.archive(ArchiverFactory.TARGZ, os, glob);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
return new WorkspaceSnapshotImpl();
}
diff --git a/core/src/main/java/hudson/Main.java b/core/src/main/java/hudson/Main.java
index 4abcf5c291449ae8be31e7957956467be9113afd..f341c88d30fb96a44b60165a3573dc78829c42e0 100644
--- a/core/src/main/java/hudson/Main.java
+++ b/core/src/main/java/hudson/Main.java
@@ -26,6 +26,7 @@ package hudson;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import jenkins.util.SystemProperties;
import hudson.util.DualOutputStream;
import hudson.util.EncodingStream;
@@ -155,6 +156,8 @@ public class Main {
ret = proc.join();
w.write(""+ret+""+(System.currentTimeMillis()-start)+"");
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
URL location = new URL(jobURL, "postBuildResult");
@@ -173,6 +176,8 @@ public class Main {
// send the data
try (InputStream in = Files.newInputStream(tmpFile.toPath())) {
org.apache.commons.io.IOUtils.copy(in, con.getOutputStream());
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
if(con.getResponseCode()!=200) {
diff --git a/core/src/main/java/hudson/PluginWrapper.java b/core/src/main/java/hudson/PluginWrapper.java
index 1a55bbc1bd248c792c113874ac47ff140b7319f7..9ca85b04aa4e694e57b3357c49a86172dbda8d03 100644
--- a/core/src/main/java/hudson/PluginWrapper.java
+++ b/core/src/main/java/hudson/PluginWrapper.java
@@ -30,6 +30,7 @@ import hudson.model.AdministrativeMonitor;
import hudson.model.Api;
import hudson.model.ModelObject;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import jenkins.YesNoMaybe;
import jenkins.model.Jenkins;
import hudson.model.UpdateCenter;
@@ -496,8 +497,11 @@ public class PluginWrapper implements Comparable, ModelObject {
*/
public void disable() throws IOException {
// creates an empty file
- OutputStream os = Files.newOutputStream(disableFile.toPath());
- os.close();
+ try (OutputStream os = Files.newOutputStream(disableFile.toPath())) {
+ os.close();
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
+ }
}
/**
diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java
index f7758cbedb92bef602e9b8af7feb1729d57d9a6b..07ff96fb007f9939cddc122f56ef8351c33c321b 100644
--- a/core/src/main/java/hudson/Util.java
+++ b/core/src/main/java/hudson/Util.java
@@ -23,6 +23,7 @@
*/
package hudson;
+import java.nio.file.InvalidPathException;
import jenkins.util.SystemProperties;
import com.sun.jna.Native;
@@ -202,6 +203,8 @@ public class Util {
int len;
while ((len = r.read(buf, 0, buf.length)) > 0)
str.append(buf, 0, len);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
return str.toString();
@@ -283,7 +286,11 @@ public class Util {
if(!f.delete() && f.exists()) {
// trouble-shooting.
- Files.deleteIfExists(f.toPath());
+ try {
+ Files.deleteIfExists(f.toPath());
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
+ }
// see https://java.net/projects/hudson/lists/users/archive/2008-05/message/357
// I suspect other processes putting files in this directory
@@ -811,6 +818,8 @@ public class Util {
public static String getDigestOf(@Nonnull File file) throws IOException {
try (InputStream is = Files.newInputStream(file.toPath())) {
return getDigestOf(new BufferedInputStream(is));
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
}
@@ -1143,7 +1152,11 @@ public class Util {
* Creates an empty file.
*/
public static void touch(@Nonnull File file) throws IOException {
- Files.newOutputStream(file.toPath()).close();
+ try {
+ Files.newOutputStream(file.toPath()).close();
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
+ }
}
/**
diff --git a/core/src/main/java/hudson/WebAppMain.java b/core/src/main/java/hudson/WebAppMain.java
index 2081a685fd5f28ea71e81550d9f653fadcd5e379..d9b11ccfb53877ee3df9488d221ef8a1c20417d4 100644
--- a/core/src/main/java/hudson/WebAppMain.java
+++ b/core/src/main/java/hudson/WebAppMain.java
@@ -26,6 +26,7 @@ package hudson;
import hudson.security.ACLContext;
import java.io.OutputStream;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import java.nio.file.StandardOpenOption;
import jenkins.util.SystemProperties;
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
@@ -278,7 +279,7 @@ public class WebAppMain implements ServletContextListener {
private void recordBootAttempt(File home) {
try (OutputStream o=Files.newOutputStream(BootFailure.getBootFailureFile(home).toPath(), StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
o.write((new Date().toString() + System.getProperty("line.separator", "\n")).toString().getBytes());
- } catch (IOException e) {
+ } catch (IOException | InvalidPathException e) {
LOGGER.log(WARNING, "Failed to record boot attempts",e);
}
}
diff --git a/core/src/main/java/hudson/XmlFile.java b/core/src/main/java/hudson/XmlFile.java
index ba1434b8f76ab2498852d620dfcd3fa34098f4f3..72d4d6c128ac605d4abd74d0d0587fb2d39af508 100644
--- a/core/src/main/java/hudson/XmlFile.java
+++ b/core/src/main/java/hudson/XmlFile.java
@@ -34,6 +34,7 @@ import hudson.model.Descriptor;
import hudson.util.AtomicFileWriter;
import hudson.util.XStream2;
import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
@@ -140,7 +141,7 @@ public final class XmlFile {
}
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
return xs.fromXML(in);
- } catch (XStreamException | Error e) {
+ } catch (XStreamException | Error | InvalidPathException e) {
throw new IOException("Unable to read "+file,e);
}
}
@@ -157,7 +158,7 @@ public final class XmlFile {
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
// TODO: expose XStream the driver from XStream
return xs.unmarshal(DEFAULT_DRIVER.createReader(in), o);
- } catch (XStreamException | Error e) {
+ } catch (XStreamException | Error | InvalidPathException e) {
throw new IOException("Unable to read "+file,e);
}
}
@@ -201,14 +202,18 @@ public final class XmlFile {
* @return Reader for the file. should be close externally once read.
*/
public Reader readRaw() throws IOException {
- InputStream fileInputStream = Files.newInputStream(file.toPath());
try {
- return new InputStreamReader(fileInputStream, sniffEncoding());
- } catch(IOException ex) {
- // Exception may happen if we fail to find encoding or if this encoding is unsupported.
- // In such case we close the underlying stream and rethrow.
- Util.closeAndLogFailures(fileInputStream, LOGGER, "FileInputStream", file.toString());
- throw ex;
+ InputStream fileInputStream = Files.newInputStream(file.toPath());
+ try {
+ return new InputStreamReader(fileInputStream, sniffEncoding());
+ } catch (IOException ex) {
+ // Exception may happen if we fail to find encoding or if this encoding is unsupported.
+ // In such case we close the underlying stream and rethrow.
+ Util.closeAndLogFailures(fileInputStream, LOGGER, "FileInputStream", file.toString());
+ throw ex;
+ }
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
}
}
@@ -288,7 +293,9 @@ public final class XmlFile {
// in such a case, assume UTF-8 rather than fail, since Jenkins internally always write XML in UTF-8
return "UTF-8";
} catch (SAXException e) {
- throw new IOException("Failed to detect encoding of "+file,e);
+ throw new IOException("Failed to detect encoding of " + file, e);
+ } catch (InvalidPathException e) {
+ throw new IOException(e);
} catch (ParserConfigurationException e) {
throw new AssertionError(e); // impossible
}
diff --git a/core/src/main/java/hudson/console/ConsoleAnnotator.java b/core/src/main/java/hudson/console/ConsoleAnnotator.java
index eab2376ddde655485a4879b7a523cb52f40b65aa..c19ac974b686064cd0adb7767065c7d04a6a3af4 100644
--- a/core/src/main/java/hudson/console/ConsoleAnnotator.java
+++ b/core/src/main/java/hudson/console/ConsoleAnnotator.java
@@ -30,6 +30,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
/**
* Annotates one line of console output.
@@ -71,15 +73,16 @@ public abstract class ConsoleAnnotator implements Serializable {
* Annotates one line.
*
* @param context
- * The object that owns the console output. Never null.
+ * The object that owns the console output. Never {@code null}.
* @param text
* Contains a single line of console output, and defines convenient methods to add markup.
- * The callee should put markup into this object. Never null.
+ * The callee should put markup into this object. Never {@code null}.
* @return
* The {@link ConsoleAnnotator} object that will annotate the next line of the console output.
- * To indicate that you are not interested in the following lines, return null.
+ * To indicate that you are not interested in the following lines, return {@code null}.
*/
- public abstract ConsoleAnnotator annotate(T context, MarkupText text );
+ @CheckForNull
+ public abstract ConsoleAnnotator annotate(@Nonnull T context, @Nonnull MarkupText text );
/**
* Cast operation that restricts T.
diff --git a/core/src/main/java/hudson/console/HudsonExceptionNote.java b/core/src/main/java/hudson/console/HudsonExceptionNote.java
index c442dff2fdb48d4caf42e692e8231bb27c76246f..83511694ceca4028e4b58011bba677d508846d23 100644
--- a/core/src/main/java/hudson/console/HudsonExceptionNote.java
+++ b/core/src/main/java/hudson/console/HudsonExceptionNote.java
@@ -1,7 +1,7 @@
/*
* The MIT License
*
- * Copyright (c) 2010-2011, CloudBees, Inc.
+ * Copyright (c) 2010-2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,73 +27,31 @@ import hudson.Extension;
import hudson.MarkupText;
import org.jenkinsci.Symbol;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
+// TODO: the implementation has been deprecated due to JENKINS-42861
+// Consider providing alternate search mechanisms (JIRA, grepcode, etc.) as proposed in
+// https://github.com/jenkinsci/jenkins/pull/2808#pullrequestreview-27467560 (JENKINS-43612)
/**
- * Placed on the beginning of the exception stack trace produced by Hudson, which in turn produces hyperlinked stack trace.
+ * Placed on the beginning of the exception stack trace produced by Jenkins,
+ * which in turn produces hyperlinked stack trace.
*
*
* Exceptions in the user code (like junit etc) should be handled differently. This is only for exceptions
- * that occur inside Hudson.
+ * that occur inside Jenkins.
*
* @author Kohsuke Kawaguchi
- * @since 1.349
+ * @since 1.349 - produces search hyperlinks to the http://stacktrace.jenkins-ci.org service
+ * @since TODO - does nothing due to JENKINS-42861
+ * @deprecated This ConsoleNote used to provide hyperlinks to the
+ * http://stacktrace.jenkins-ci.org/ service, which is dead now (JENKINS-42861).
+ * This console note does nothing right now.
*/
+@Deprecated
public class HudsonExceptionNote extends ConsoleNote