Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d5ba10b
Replace if-cascades with switch
strangelookingnerd Jan 5, 2026
b58d88d
Reference to empty collection field replaced with method call (Java 5)
strangelookingnerd Jan 5, 2026
f7c092c
Anonymous type replaced with lambda (Java 8)
strangelookingnerd Jan 5, 2026
7a427ff
Replaced lambda with method reference (Java 8)
strangelookingnerd Jan 5, 2026
25f34d9
Statement lambda replaced with expression lambda (Java 8)
strangelookingnerd Jan 5, 2026
b3dd480
Loop replaced with 'Collection.removeIf()' (Java 8)
strangelookingnerd Jan 5, 2026
6ae4f30
Null check replaced with method call (Java 9)
strangelookingnerd Jan 5, 2026
0c7e7e2
Statement replaced with enhanced 'switch' (Java 14)
strangelookingnerd Jan 5, 2026
a4edf69
Use text blocks (Java 15)
strangelookingnerd Jan 5, 2026
ecc8116
Use pattern variable (Java 16)
strangelookingnerd Jan 5, 2026
12fd903
Replace if-cascades with switch
strangelookingnerd Jan 6, 2026
9a144f6
Use 'Comparator' combinator
strangelookingnerd Jan 6, 2026
6f96240
Null check replaced with method call (Java 9)
strangelookingnerd Jan 6, 2026
c83ad11
Use pattern variable (Java 16)
strangelookingnerd Jan 6, 2026
c480034
Use record pattern (Java 21)
strangelookingnerd Jan 6, 2026
70b01c5
Use SequencedCollection method (Java 21)
strangelookingnerd Jan 6, 2026
3afc59a
Replaced lambda with method reference (Java 8)
strangelookingnerd Jan 6, 2026
a474bde
Cleanup unused imports
strangelookingnerd Jan 6, 2026
d6ae31d
Cleanup migrations (move comments, formatting, spotbugs...)
strangelookingnerd Jan 6, 2026
46c36c1
Merge branch 'master' into java-level-migrations
MarkEWaite Jan 12, 2026
1e4eda5
Remove duplicate comment
MarkEWaite Jan 12, 2026
ea4f7ae
Remove blank line that may confuse Copilot
MarkEWaite Jan 12, 2026
55bedd4
Inject comments into source line
MarkEWaite Jan 12, 2026
cb162ac
Simplify with return value of switch statement
MarkEWaite Jan 12, 2026
0653080
Merge branch 'master' into java-level-migrations
MarkEWaite Jan 12, 2026
573262e
Merge branch 'master' into java-level-migrations
MarkEWaite Jan 17, 2026
b2e4c8f
Merge branch 'master' into java-level-migrations
MarkEWaite Jan 18, 2026
a22a2cc
Merge branch 'master' into java-level-migrations
MarkEWaite Jan 20, 2026
cb73c11
Use pattern matching instanceof in one more case
MarkEWaite Jan 20, 2026
84a4ae3
Don't lose the NetBeans comment that was there before
MarkEWaite Jan 20, 2026
c3fe756
Remove TODO for Java 21 pattern use, implemented
MarkEWaite Jan 20, 2026
e5bf2fe
Align comments with Unicode character they describe
MarkEWaite Jan 20, 2026
3bb6bfd
Merge branch 'master' into java-level-migrations
MarkEWaite Jan 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions cli/src/main/java/hudson/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,40 +138,45 @@ public static int _main(String[] _args) throws Exception {

while (!args.isEmpty()) {
String head = args.get(0);
if (head.equals("-version")) {
System.out.println("Version: " + computeVersion());
return 0;
}
if (head.equals("-http")) {
if (mode != null) {
printUsage("-http clashes with previously defined mode " + mode);
return -1;
switch (head) {
case "-version" -> {
System.out.println("Version: " + computeVersion());
return 0;
}
mode = Mode.HTTP;
args = args.subList(1, args.size());
continue;
}
if (head.equals("-ssh")) {
if (mode != null) {
printUsage("-ssh clashes with previously defined mode " + mode);
return -1;
case "-http" -> {
if (mode != null) {
printUsage("-http clashes with previously defined mode " + mode);
return -1;
}
mode = Mode.HTTP;
args = args.subList(1, args.size());
continue;
}
mode = Mode.SSH;
args = args.subList(1, args.size());
continue;
}
if (head.equals("-webSocket")) {
if (mode != null) {
printUsage("-webSocket clashes with previously defined mode " + mode);
case "-ssh" -> {
if (mode != null) {
printUsage("-ssh clashes with previously defined mode " + mode);
return -1;
}
mode = Mode.SSH;
args = args.subList(1, args.size());
continue;
}
case "-webSocket" -> {
if (mode != null) {
printUsage("-webSocket clashes with previously defined mode " + mode);
return -1;
}
mode = Mode.WEB_SOCKET;
args = args.subList(1, args.size());
continue;
}
case "-remoting" -> {
printUsage("-remoting mode is no longer supported");
return -1;
}
mode = Mode.WEB_SOCKET;
args = args.subList(1, args.size());
continue;
}
if (head.equals("-remoting")) {
printUsage("-remoting mode is no longer supported");
return -1;
default -> {
// continue
}
}
if (head.equals("-s") && args.size() >= 2) {
url = args.get(1);
Expand Down
77 changes: 42 additions & 35 deletions cli/src/main/java/hudson/cli/PlainCLIProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,33 @@ abstract static class ServerSide extends EitherSide {
@Override
protected final boolean handle(Op op, DataInputStream dis) throws IOException {
assert op.clientSide;
switch (op) {
case ARG:
onArg(dis.readUTF());
return true;
case LOCALE:
onLocale(dis.readUTF());
return true;
case ENCODING:
onEncoding(dis.readUTF());
return true;
case START:
onStart();
return true;
case STDIN:
onStdin(dis.readAllBytes());
return true;
case END_STDIN:
onEndStdin();
return true;
default:
return false;
}
return switch (op) {
case ARG -> {
onArg(dis.readUTF());
yield true;
}
case LOCALE -> {
onLocale(dis.readUTF());
yield true;
}
case ENCODING -> {
onEncoding(dis.readUTF());
yield true;
}
case START -> {
onStart();
yield true;
}
case STDIN -> {
onStdin(dis.readAllBytes());
yield true;
}
case END_STDIN -> {
onEndStdin();
yield true;
}
default -> false;
};
}

protected abstract void onArg(String text);
Expand Down Expand Up @@ -321,19 +326,21 @@ abstract static class ClientSide extends EitherSide {
@Override
protected boolean handle(Op op, DataInputStream dis) throws IOException {
assert !op.clientSide;
switch (op) {
case EXIT:
onExit(dis.readInt());
return true;
case STDOUT:
onStdout(dis.readAllBytes());
return true;
case STDERR:
onStderr(dis.readAllBytes());
return true;
default:
return false;
}
return switch (op) {
case EXIT -> {
onExit(dis.readInt());
yield true;
}
case STDOUT -> {
onStdout(dis.readAllBytes());
yield true;
}
case STDERR -> {
onStderr(dis.readAllBytes());
yield true;
}
default -> false;
};
}

protected abstract void onExit(int code);
Expand Down
12 changes: 3 additions & 9 deletions cli/src/main/java/hudson/cli/SSHCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.util.QuotedStringTokenizer;
import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
Expand All @@ -45,7 +43,6 @@
import org.apache.sshd.client.future.ConnectFuture;
import org.apache.sshd.client.keyverifier.DefaultKnownHostsServerKeyVerifier;
import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier;
import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.future.WaitableFuture;
import org.apache.sshd.common.util.io.input.NoCloseInputStream;
Expand Down Expand Up @@ -86,12 +83,9 @@ static int sshConnection(String jenkinsUrl, String user, List<String> args, Priv

try (SshClient client = SshClient.setUpDefaultClient()) {

KnownHostsServerKeyVerifier verifier = new DefaultKnownHostsServerKeyVerifier(new ServerKeyVerifier() {
@Override
public boolean verifyServerKey(ClientSession clientSession, SocketAddress remoteAddress, PublicKey serverKey) {
CLI.LOGGER.log(Level.WARNING, "Unknown host key for {0}", remoteAddress.toString());
return !strictHostKey;
}
KnownHostsServerKeyVerifier verifier = new DefaultKnownHostsServerKeyVerifier((clientSession, remoteAddress, serverKey) -> {
CLI.LOGGER.log(Level.WARNING, "Unknown host key for {0}", remoteAddress.toString());
return !strictHostKey;
}, true);

client.setServerKeyVerifier(verifier);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/EnvVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private void cutCycle(List<String> cycle) {
}

// if not, cut the reference to the first one.
cutCycleAt(cycle.get(0), cycle);
cutCycleAt(cycle.getFirst(), cycle);
}

/**
Expand Down
18 changes: 7 additions & 11 deletions core/src/main/java/hudson/ExtensionFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@
.flatMap(Collection::stream)
.filter(m -> m.getAnnotation(PostConstruct.class) != null || m.getAnnotation(javax.annotation.PostConstruct.class) != null)
.findFirst()
.ifPresent(method -> methods.add(0, method));
.ifPresent(methods::addFirst);
c = c.getSuperclass();
}

Expand Down Expand Up @@ -788,16 +788,12 @@

private static Class<?> getClassFromIndex(IndexItem<Extension, Object> item) throws InstantiationException {
AnnotatedElement e = item.element();
Class<?> extType;
if (e instanceof Class) {
extType = (Class) e;
} else if (e instanceof Field) {
extType = ((Field) e).getType();
} else if (e instanceof Method) {
extType = ((Method) e).getReturnType();
} else {
throw new AssertionError();
}
Class<?> extType = switch (e) {

Check warning on line 791 in core/src/main/java/hudson/ExtensionFinder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 791 is only partially covered, one branch is missing
case Class aClass -> aClass;
case Field field -> field.getType();
case Method method -> method.getReturnType();
case null, default -> throw new AssertionError();
};
return extType;
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/ExtensionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public static <T> ExtensionList<T> create(Jenkins jenkins, Class<T> type) {
} else if (all.size() != 1) {
throw new IllegalStateException("Expected 1 instance of " + type.getName() + " but got " + all.size());
}
return all.get(0);
return all.getFirst();
}

/**
Expand All @@ -474,7 +474,7 @@ public static <T> ExtensionList<T> create(Jenkins jenkins, Class<T> type) {
public static @NonNull <U> U lookupFirst(Class<U> type) {
var all = lookup(type);
if (!all.isEmpty()) {
return all.get(0);
return all.getFirst();
} else {
if (Main.isUnitTest) {
throw new IllegalStateException("Found no instances of " + type.getName() +
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 @@ -350,15 +350,15 @@
if (i == 0) {
// If absolute path, just remove: /../something
// If relative path, not collapsible so leave as-is
tokens.remove(0);
if (!tokens.isEmpty()) token += tokens.remove(0);
tokens.removeFirst();
if (!tokens.isEmpty()) token += tokens.removeFirst();

Check warning on line 354 in core/src/main/java/hudson/FilePath.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 354 is only partially covered, one branch is missing
if (!isAbsolute) buf.append(token);
} else {
// Normalize: remove something/.. plus separator before/after
i -= 2;
for (int j = 0; j < 3; j++) tokens.remove(i);
if (i > 0) tokens.remove(i - 1);
else if (!tokens.isEmpty()) tokens.remove(0);
else if (!tokens.isEmpty()) tokens.removeFirst();
}
} else
i += 2;
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
Expand Down Expand Up @@ -1278,11 +1279,7 @@ public static boolean hasAnyPermission(Object object, Permission[] permissions)
return hasAnyPermission((AccessControlled) object, permissions);
else {
AccessControlled ac = Stapler.getCurrentRequest2().findAncestorObject(AccessControlled.class);
if (ac != null) {
return hasAnyPermission(ac, permissions);
}

return hasAnyPermission(Jenkins.get(), permissions);
return hasAnyPermission(Objects.requireNonNullElseGet(ac, Jenkins::get), permissions);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/MarkupText.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void addMarkup(int startPos, int endPos, String startTag, String endTag)
// <b><i>abc</i></b>, not <b><i>abc</b></i>. Also, we'd like <b>abc</b><i>def</i>,
// not <b>abc<i></b>def</i>. Do this by inserting them to different places.
tags.add(new Tag(startPos, startTag));
tags.add(0, new Tag(endPos, endTag));
tags.addFirst(new Tag(endPos, endTag));
}

public void addMarkup(int pos, String tag) {
Expand Down
Loading
Loading