Skip to content

Commit

Permalink
Merge branch 'master' into update-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Dec 23, 2021
2 parents 0298e43 + e16c5eb commit 959979d
Show file tree
Hide file tree
Showing 78 changed files with 359 additions and 442 deletions.
4 changes: 2 additions & 2 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ THE SOFTWARE.
<dependency> <!-- https://docs.spring.io/spring-security/site/docs/5.4.0-M1/reference/html5/#getting-maven-no-boot -->
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>5.6.0</version>
<version>5.6.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -173,7 +173,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
<version>1.15</version>
<version>1.16</version>
</dependency>

<dependency>
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/hudson/cli/CLIConnectionFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.cli;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
Expand Down Expand Up @@ -33,7 +34,7 @@ public CLIConnectionFactory basicAuth(String username, String password) {
* Cf. {@code BasicHeaderApiTokenAuthenticator}.
*/
public CLIConnectionFactory basicAuth(String userInfo) {
return authorization("Basic " + Base64.getEncoder().encodeToString(userInfo.getBytes()));
return authorization("Basic " + Base64.getEncoder().encodeToString(userInfo.getBytes(StandardCharsets.UTF_8)));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions cli/src/main/java/hudson/cli/PrivateKeyProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package hudson.cli;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.logging.Level.FINE;

import java.io.ByteArrayInputStream;
Expand All @@ -32,6 +31,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
Expand Down Expand Up @@ -134,7 +134,7 @@ private static String readPemFile(File f) throws IOException{
DataInputStream dis = new DataInputStream(is)) {
byte[] bytes = new byte[(int) f.length()];
dis.readFully(bytes);
return new String(bytes);
return new String(bytes, StandardCharsets.UTF_8);
} catch (InvalidPathException e) {
throw new IOException(e);
}
Expand All @@ -143,7 +143,7 @@ private static String readPemFile(File f) throws IOException{
public static KeyPair loadKey(String pemString, String passwd) throws IOException, GeneralSecurityException {
Iterable<KeyPair> itr = SecurityUtils.loadKeyPairIdentities(null,
new PathResource(Paths.get("key")),
new ByteArrayInputStream(pemString.getBytes(UTF_8)),
new ByteArrayInputStream(pemString.getBytes(StandardCharsets.UTF_8)),
FilePasswordProvider.of(passwd));
long numLoaded = itr == null ? 0 : StreamSupport.stream(itr.spliterator(), false).count();
if (numLoaded <= 0) {
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/ExtensionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -327,7 +328,7 @@ private List<ExtensionComponent<T>> ensureLoaded() {
* Chooses the object that locks the loading of the extension instances.
*/
protected Object getLoadLock() {
return jenkins.lookup.setIfNull(Lock.class,new Lock());
return Objects.requireNonNull(jenkins).lookup.setIfNull(Lock.class,new Lock());
}

/**
Expand Down Expand Up @@ -379,7 +380,7 @@ protected List<ExtensionComponent<T>> load() {
LOGGER.log(Level.FINER, String.format("Loading ExtensionList '%s' from", extensionType.getName()), new Throwable("Only present for stacktrace information"));
}

return jenkins.getPluginManager().getPluginStrategy().findComponents(extensionType, hudson);
return Objects.requireNonNull(jenkins).getPluginManager().getPluginStrategy().findComponents(extensionType, hudson);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.FileSystemException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
Expand Down Expand Up @@ -2279,7 +2280,7 @@ private static class ReadToString extends MasterToSlaveFileCallable<String> {
private static final long serialVersionUID = 1L;
@Override
public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return new String(Files.readAllBytes(fileToPath(f)));
return new String(Files.readAllBytes(fileToPath(f)), Charset.defaultCharset());
}
}

Expand Down Expand Up @@ -2336,7 +2337,7 @@ private static class Write extends MasterToSlaveFileCallable<Void> {
public Void invoke(File f, VirtualChannel channel) throws IOException {
mkdirs(f.getParentFile());
try (OutputStream fos = Files.newOutputStream(fileToPath(f));
Writer w = encoding != null ? new OutputStreamWriter(fos, encoding) : new OutputStreamWriter(fos)) {
Writer w = encoding != null ? new OutputStreamWriter(fos, encoding) : new OutputStreamWriter(fos, Charset.defaultCharset())) {
w.write(content);
}
return null;
Expand Down Expand Up @@ -3611,5 +3612,4 @@ public boolean accept(File file) {
}
private static final long serialVersionUID = 1L;
}

}
14 changes: 7 additions & 7 deletions core/src/main/java/hudson/PluginWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -972,21 +972,21 @@ public boolean hasLicensesXml() {
if (dependency == null) {
PluginWrapper failedDependency = NOTICE.getPlugin(d.shortName);
if (failedDependency != null) {
dependencyErrors.put(Messages.PluginWrapper_failed_to_load_dependency(failedDependency.getLongName(), failedDependency.getVersion()), true);
dependencyErrors.put(Messages.PluginWrapper_failed_to_load_dependency_2(failedDependency.getLongName(), failedDependency.getShortName(), failedDependency.getVersion()), true);
break;
} else {
dependencyErrors.put(Messages.PluginWrapper_missing(d.shortName, d.version), false);
}
} else {
if (dependency.isActive()) {
if (isDependencyObsolete(d, dependency)) {
versionDependencyError(Messages.PluginWrapper_obsolete(dependency.getLongName(), dependency.getVersion(), d.version), dependency.getVersion(), d.version);
versionDependencyError(Messages.PluginWrapper_obsolete_2(dependency.getLongName(), dependency.getShortName(), dependency.getVersion(), d.version), dependency.getVersion(), d.version);
}
} else {
if (isDependencyObsolete(d, dependency)) {
versionDependencyError(Messages.PluginWrapper_disabledAndObsolete(dependency.getLongName(), dependency.getVersion(), d.version), dependency.getVersion(), d.version);
versionDependencyError(Messages.PluginWrapper_obsolete_2(dependency.getLongName(), dependency.getShortName(), dependency.getVersion(), d.version), dependency.getVersion(), d.version);
} else {
dependencyErrors.put(Messages.PluginWrapper_disabled(dependency.getLongName()), false);
dependencyErrors.put(Messages.PluginWrapper_disabled_2(dependency.getLongName(), dependency.getShortName()), false);
}
}

Expand All @@ -997,7 +997,7 @@ public boolean hasLicensesXml() {
PluginWrapper dependency = parent.getPlugin(d.shortName);
if (dependency != null && dependency.isActive()) {
if (isDependencyObsolete(d, dependency)) {
versionDependencyError(Messages.PluginWrapper_obsolete(dependency.getLongName(), dependency.getVersion(), d.version), dependency.getVersion(), d.version);
versionDependencyError(Messages.PluginWrapper_obsolete_2(dependency.getLongName(), dependency.getShortName(), dependency.getVersion(), d.version), dependency.getVersion(), d.version);
} else {
dependencies.add(d);
}
Expand All @@ -1006,7 +1006,7 @@ public boolean hasLicensesXml() {
if (!dependencyErrors.isEmpty()) {
NOTICE.addPlugin(this);
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append(Messages.PluginWrapper_failed_to_load_plugin(getLongName(), getVersion())).append(System.lineSeparator());
messageBuilder.append(Messages.PluginWrapper_failed_to_load_plugin_2(getLongName(), getShortName(), getVersion())).append(System.lineSeparator());
for (Iterator<String> iterator = dependencyErrors.keySet().iterator(); iterator.hasNext(); ) {
String dependencyError = iterator.next();
messageBuilder.append(" - ").append(dependencyError);
Expand All @@ -1029,7 +1029,7 @@ private boolean isDependencyObsolete(Dependency d, PluginWrapper dependency) {
*/
private void versionDependencyError(String message, String actual, String minimum) {
if (isSnapshot(actual) || isSnapshot(minimum)) {
LOGGER.log(WARNING, "Suppressing dependency error in {0} v{1}: {2}", new Object[] {getLongName(), getVersion(), message});
LOGGER.log(WARNING, "Suppressing dependency error in {0} v{1}: {2}", new Object[] {getShortName(), getVersion(), message});
} else {
dependencyErrors.put(message, false);
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/Proc.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -354,7 +355,7 @@ public int join() throws InterruptedException, IOException {
// } catch (IOException x) {
// LOGGER.log(Level.FINE,"stderr termination failed",x);
// }
out.write(msg.getBytes());
out.write(msg.getBytes(Charset.defaultCharset()));
out.write('\n');
}
return r;
Expand Down
22 changes: 2 additions & 20 deletions core/src/main/java/hudson/WebAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.io.OutputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.StandardOpenOption;
Expand All @@ -71,8 +72,6 @@
import javax.servlet.ServletContextListener;
import javax.servlet.ServletResponse;
import javax.servlet.SessionTrackingMode;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import jenkins.model.Jenkins;
import jenkins.util.JenkinsJVM;
import jenkins.util.SystemProperties;
Expand Down Expand Up @@ -235,23 +234,6 @@ public Locale get() {
throw new NoTempDir(e);
}

// Tomcat breaks XSLT with JDK 5.0 and onward. Check if that's the case, and if so,
// try to correct it
try {
TransformerFactory.newInstance();
// if this works we are all happy
} catch (TransformerFactoryConfigurationError x) {
// no it didn't.
LOGGER.log(WARNING, "XSLT not configured correctly. Hudson will try to fix this. See https://bz.apache.org/bugzilla/show_bug.cgi?id=40895 for more details",x);
System.setProperty(TransformerFactory.class.getName(),"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
try {
TransformerFactory.newInstance();
LOGGER.info("XSLT is set to the JAXP RI in JRE");
} catch(TransformerFactoryConfigurationError y) {
LOGGER.log(SEVERE, "Failed to correct the problem.");
}
}

installExpressionFactory(event);

context.setAttribute(APP,new HudsonIsLoading());
Expand Down Expand Up @@ -312,7 +294,7 @@ public void joinInit() throws InterruptedException {
*/
private void recordBootAttempt(File home) {
try (OutputStream o=Files.newOutputStream(BootFailure.getBootFailureFile(home).toPath(), StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
o.write((new Date() + System.getProperty("line.separator", "\n")).getBytes());
o.write((new Date() + System.getProperty("line.separator", "\n")).getBytes(Charset.defaultCharset()));
} catch (IOException | InvalidPathException e) {
LOGGER.log(WARNING, "Failed to record boot attempts",e);
}
Expand Down
21 changes: 17 additions & 4 deletions core/src/main/java/hudson/cli/CLICommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -404,7 +405,11 @@ protected void printUsage(PrintStream stderr, CmdLineParser p) {
public final String getSingleLineSummary() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
getCmdLineParser().printSingleLineUsage(out);
return out.toString();
try {
return out.toString(getClientCharset().name());
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
}

/**
Expand All @@ -414,7 +419,11 @@ public final String getSingleLineSummary() {
public final String getUsage() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
getCmdLineParser().printUsage(out);
return out.toString();
try {
return out.toString(getClientCharset().name());
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
}

/**
Expand All @@ -427,7 +436,11 @@ public final String getLongDescription() {

printUsageSummary(ps);
ps.close();
return out.toString();
try {
return out.toString(getClientCharset().name());
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
}

/**
Expand Down Expand Up @@ -457,7 +470,7 @@ public void setClientCharset(@NonNull Charset encoding) {
this.encoding = encoding;
}

protected @NonNull Charset getClientCharset() throws IOException, InterruptedException {
protected @NonNull Charset getClientCharset() {
if (encoding != null) {
return encoding;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/console/AnnotatedLargeText.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public long writeHtmlTo(long start, Writer w) throws IOException {
oos.close();
StaplerResponse rsp = Stapler.getCurrentResponse();
if (rsp!=null)
rsp.setHeader("X-ConsoleAnnotator", new String(Base64.getEncoder().encode(baos.toByteArray())));
rsp.setHeader("X-ConsoleAnnotator", Base64.getEncoder().encodeToString(baos.toByteArray()));
return r;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public ConsoleAnnotator<T> annotate(T context, MarkupText text) {
}
} catch (IOException | ClassNotFoundException e) {
// if we failed to resurrect an annotation, ignore it.
LOGGER.log(Level.FINE, "Failed to resurrect annotation from \"" + StringEscapeUtils.escapeJava(new String(in, next, rest)) + "\"", e);
LOGGER.log(Level.FINE, "Failed to resurrect annotation from \"" + StringEscapeUtils.escapeJava(new String(in, next, rest, Charset.defaultCharset())) + "\"", e);
}

int bytesUsed = rest - b.available(); // bytes consumed by annotations
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/hudson/console/ConsoleNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.OutputStream;
import java.io.Serializable;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
Expand Down Expand Up @@ -325,11 +326,13 @@ public static void skip(DataInputStream in) throws IOException {
* Preamble of the encoded form. ANSI escape sequence to stop echo back
* plus a few magic characters.
*/
public static final byte[] PREAMBLE = PREAMBLE_STR.getBytes();
@SuppressFBWarnings(value = "MS_PKGPROTECT", justification = "used in several plugins")
public static final byte[] PREAMBLE = PREAMBLE_STR.getBytes(StandardCharsets.UTF_8);
/**
* Post amble is the ANSI escape sequence that brings back the echo.
*/
public static final byte[] POSTAMBLE = POSTAMBLE_STR.getBytes();
@SuppressFBWarnings(value = "MS_PKGPROTECT", justification = "used in several plugins")
public static final byte[] POSTAMBLE = POSTAMBLE_STR.getBytes(StandardCharsets.UTF_8);

/**
* Locates the preamble in the given buffer.
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/AbstractBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.ref.WeakReference;
import java.nio.channels.ClosedByInterruptException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
Expand Down Expand Up @@ -668,7 +669,7 @@ public void defaultCheckout() throws IOException, InterruptedException {
}
} catch (AbortException e) {
listener.error(e.getMessage());
} catch (InterruptedIOException e) {
} catch (ClosedByInterruptException | InterruptedIOException e) {
throw (InterruptedException)new InterruptedException().initCause(e);
} catch (IOException e) {
// checkout error not yet reported
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ protected void checkRename(@NonNull String newName) throws Failure {
* Not all the Items need to support this operation, but if you decide to do so,
* you can use this method.
*/
@SuppressFBWarnings(value = "SWL_SLEEP_WITH_LOCK_HELD", justification = "no big deal")
protected void renameTo(final String newName) throws IOException {

if (!isNameEditable()) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/model/AutoCompletionCandidates.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package hudson.model;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.search.Search;
import hudson.search.UserSearchProperty;
import java.io.IOException;
Expand Down Expand Up @@ -108,6 +109,7 @@ public static <T extends Item> AutoCompletionCandidates ofJobNames(final Class<T
* The nearby contextual {@link ItemGroup} to resolve relative job names from.
* @since 1.553
*/
@SuppressFBWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION", justification = "no big deal")
public static <T extends Item> AutoCompletionCandidates ofJobNames(final Class<T> type, final String value, ItemGroup container) {
final AutoCompletionCandidates candidates = new AutoCompletionCandidates();
class Visitor extends ItemVisitor {
Expand Down
Loading

0 comments on commit 959979d

Please sign in to comment.