diff --git a/core/src/main/java/org/kohsuke/stapler/CaptureParameterNameTransformation.java b/core/src/main/java/org/kohsuke/stapler/CaptureParameterNameTransformation.java index 6a456dc13b..0f784e56e1 100644 --- a/core/src/main/java/org/kohsuke/stapler/CaptureParameterNameTransformation.java +++ b/core/src/main/java/org/kohsuke/stapler/CaptureParameterNameTransformation.java @@ -36,7 +36,6 @@ import org.codehaus.groovy.transform.GroovyASTTransformation; import org.kohsuke.MetaInfServices; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -60,8 +59,8 @@ private void handleClasses(List classNodes) { } // set of annotation class names to capture - private static final Set CONSTRUCTOR_ANN = Collections.singleton(DataBoundConstructor.class.getName()); - private static final Set INJECTED_PARAMETER_ANN = Collections.singleton(InjectedParameter.class.getName()); + private static final Set CONSTRUCTOR_ANN = Set.of(DataBoundConstructor.class.getName()); + private static final Set INJECTED_PARAMETER_ANN = Set.of(InjectedParameter.class.getName()); private void handleMethods(List methods) { for (MethodNode m : methods) diff --git a/core/src/main/java/org/kohsuke/stapler/Stapler.java b/core/src/main/java/org/kohsuke/stapler/Stapler.java index 1ba45ab2c6..9b36115088 100644 --- a/core/src/main/java/org/kohsuke/stapler/Stapler.java +++ b/core/src/main/java/org/kohsuke/stapler/Stapler.java @@ -52,7 +52,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.JarURLConnection; import java.net.MalformedURLException; @@ -60,6 +59,7 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -671,11 +671,7 @@ private String getMimeType(String fileName) { // File(String) does fs.normalize, which is really forgiving in fixing up // malformed stuff. I couldn't make the other URL.toURI() or File(URI) work // in all the cases that we test - try { - return new File(URLDecoder.decode(urlstr.substring(5),"UTF-8")); - } catch (UnsupportedEncodingException x) { - throw new AssertionError(x); - } + return new File(URLDecoder.decode(urlstr.substring(5), StandardCharsets.UTF_8)); } /** diff --git a/core/src/main/java/org/kohsuke/stapler/TokenList.java b/core/src/main/java/org/kohsuke/stapler/TokenList.java index b86aea1d5a..0041347632 100644 --- a/core/src/main/java/org/kohsuke/stapler/TokenList.java +++ b/core/src/main/java/org/kohsuke/stapler/TokenList.java @@ -168,14 +168,14 @@ public static String decode(String s) { } } else { if (baos.size()>0) { - buf.append(new String(baos.toByteArray(),StandardCharsets.UTF_8)); + buf.append(baos.toString(StandardCharsets.UTF_8)); baos.reset(); } buf.append(c); } } if (baos.size()>0) - buf.append(new String(baos.toByteArray(),StandardCharsets.UTF_8)); + buf.append(baos.toString(StandardCharsets.UTF_8)); return buf.toString(); } diff --git a/core/src/main/java/org/kohsuke/stapler/bind/Bound.java b/core/src/main/java/org/kohsuke/stapler/bind/Bound.java index 68b924e7e4..299328a223 100644 --- a/core/src/main/java/org/kohsuke/stapler/bind/Bound.java +++ b/core/src/main/java/org/kohsuke/stapler/bind/Bound.java @@ -30,7 +30,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.Set; /** * Handles to the object bound via {@link BoundObjectTable}. @@ -71,13 +71,13 @@ public final String getProxyScript() { for (Method m : getTarget().getClass().getMethods()) { Collection names; if (m.getName().startsWith("js")) { - names = Collections.singleton(camelize(m.getName().substring(2))); + names = Set.of(camelize(m.getName().substring(2))); } else { JavaScriptMethod a = m.getAnnotation(JavaScriptMethod.class); if (a!=null) { names = Arrays.asList(a.name()); if (names.isEmpty()) - names = Collections.singleton(m.getName()); + names = Set.of(m.getName()); } else continue; } diff --git a/core/src/main/java/org/kohsuke/stapler/export/Model.java b/core/src/main/java/org/kohsuke/stapler/export/Model.java index a9bc97402e..bb80497281 100644 --- a/core/src/main/java/org/kohsuke/stapler/export/Model.java +++ b/core/src/main/java/org/kohsuke/stapler/export/Model.java @@ -29,7 +29,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Properties; @@ -121,7 +120,7 @@ public class Model { * Gets all the exported properties. */ public List getProperties() { - return Collections.unmodifiableList(Arrays.asList(properties)); + return List.of(properties); } /** diff --git a/core/src/main/java/org/kohsuke/stapler/framework/io/WriterOutputStream.java b/core/src/main/java/org/kohsuke/stapler/framework/io/WriterOutputStream.java index 09d4bedc18..66e2593906 100644 --- a/core/src/main/java/org/kohsuke/stapler/framework/io/WriterOutputStream.java +++ b/core/src/main/java/org/kohsuke/stapler/framework/io/WriterOutputStream.java @@ -87,8 +87,7 @@ public void flush() throws IOException { private void flushOutput() throws IOException { writer.write(out.array(),0,out.position()); - // Downcasting to Buffer is needed to avoid NoSuchMethodError errors because Java 11 uses covariance in the ByteBuffer return type. - ((Buffer) out).clear(); + out.clear(); } @Override @@ -97,8 +96,7 @@ public void close() throws IOException { flushOutput(); writer.close(); - // Downcasting to Buffer is needed to avoid NoSuchMethodError errors because Java 11 uses covariance in the ByteBuffer return type. - ((Buffer) buf).rewind(); + buf.rewind(); } /** @@ -113,8 +111,7 @@ public void close() throws IOException { * if true, tell the decoder that all the input bytes are ready. */ private void decode(boolean last) throws IOException { - // Downcasting to Buffer is needed to avoid NoSuchMethodError errors because Java 11 uses covariance in the ByteBuffer return type. - ((Buffer) buf).flip(); + buf.flip(); while(true) { CoderResult r = decoder.decode(buf, out, last); if(r==CoderResult.OVERFLOW) { diff --git a/core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java b/core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java index 258e62508e..5eaf2089da 100644 --- a/core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java +++ b/core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java @@ -12,7 +12,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; -import javax.lang.model.util.ElementScanner6; +import javax.lang.model.util.ElementScanner9; import java.io.IOException; import java.util.HashSet; import java.util.Properties; @@ -31,7 +31,7 @@ public class ConstructorProcessor extends AbstractProcessorImpl { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { try { - ElementScanner6 scanner = new ElementScanner6() { + ElementScanner9 scanner = new ElementScanner9() { Set enclosingElementsWritten = new HashSet<>(); boolean messagePrinted; diff --git a/core/src/test/java/org/kohsuke/stapler/RequestImplTest.java b/core/src/test/java/org/kohsuke/stapler/RequestImplTest.java index da57a4bcb7..9af118ddb6 100644 --- a/core/src/test/java/org/kohsuke/stapler/RequestImplTest.java +++ b/core/src/test/java/org/kohsuke/stapler/RequestImplTest.java @@ -122,7 +122,7 @@ public int getContentLength() { @Override public Enumeration getParameterNames() { - return Collections.enumeration(Collections.singletonList("p1")); + return Collections.enumeration(List.of("p1")); } @Override diff --git a/core/src/test/java/org/kohsuke/stapler/export/ModelTest.java b/core/src/test/java/org/kohsuke/stapler/export/ModelTest.java index b26eaca5b0..cd8d250182 100644 --- a/core/src/test/java/org/kohsuke/stapler/export/ModelTest.java +++ b/core/src/test/java/org/kohsuke/stapler/export/ModelTest.java @@ -27,7 +27,6 @@ import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.util.Collection; -import java.util.Collections; import java.util.List; import org.junit.Assert; @@ -53,7 +52,7 @@ public static class Impl implements GenericInterface { @Override @Exported public List get() { - return Collections.singletonList(42); + return List.of(42); } } diff --git a/core/src/test/java/org/kohsuke/stapler/export/XMLDataWriterTest.java b/core/src/test/java/org/kohsuke/stapler/export/XMLDataWriterTest.java index 047e930ee6..e7fd11cfce 100644 --- a/core/src/test/java/org/kohsuke/stapler/export/XMLDataWriterTest.java +++ b/core/src/test/java/org/kohsuke/stapler/export/XMLDataWriterTest.java @@ -4,9 +4,9 @@ import java.io.StringReader; import java.io.StringWriter; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Set; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -35,7 +35,7 @@ public String getName(){ @Exported public Collection getJobs(){ - return Collections.singleton(new Job()); + return Set.of(new Job()); } } @@ -65,12 +65,12 @@ public String getName() { // @Exported(visibility = 2) @Override public Iterator iterator() { - return Collections.singleton(new ParameterValue()).iterator(); + return Set.of(new ParameterValue()).iterator(); } @Exported(visibility = 2) public List getParameters(){ - return Collections.singletonList(new ParameterValue()); + return List.of(new ParameterValue()); } } diff --git a/core/src/test/java/org/kohsuke/stapler/lang/KlassTest.java b/core/src/test/java/org/kohsuke/stapler/lang/KlassTest.java index 48206f641d..c0e91eb8dc 100644 --- a/core/src/test/java/org/kohsuke/stapler/lang/KlassTest.java +++ b/core/src/test/java/org/kohsuke/stapler/lang/KlassTest.java @@ -56,7 +56,7 @@ private static final class FooClass { public Object doDynamic(String token) { // Just return something potentially routable - return new Integer(0); + return Integer.valueOf(0); } } } diff --git a/groovy/src/main/java/org/kohsuke/stapler/jelly/groovy/GroovyFacet.java b/groovy/src/main/java/org/kohsuke/stapler/jelly/groovy/GroovyFacet.java index bcc0202223..75a768a728 100644 --- a/groovy/src/main/java/org/kohsuke/stapler/jelly/groovy/GroovyFacet.java +++ b/groovy/src/main/java/org/kohsuke/stapler/jelly/groovy/GroovyFacet.java @@ -40,7 +40,6 @@ import javax.servlet.ServletException; import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.logging.Level; @@ -99,7 +98,7 @@ public boolean handleIndexRequest(RequestImpl req, ResponseImpl rsp, Object node handleIndexRequest(nodeMetaClass.loadTearOff(GroovyServerPageTearOff.class), scriptExecutor, req, rsp, node); } - private static final Set> TEAROFF_TYPES = Collections.singleton(GroovyClassTearOff.class); + private static final Set> TEAROFF_TYPES = Set.of(GroovyClassTearOff.class); - private static final Set EXTENSION = Collections.singleton(".groovy"); + private static final Set EXTENSION = Set.of(".groovy"); } diff --git a/groovy/src/test/java/org/kohsuke/stapler/jelly/groovy/GroovyClassLoaderTearOffTest.java b/groovy/src/test/java/org/kohsuke/stapler/jelly/groovy/GroovyClassLoaderTearOffTest.java index d238dcd1b6..5fdeaa596d 100644 --- a/groovy/src/test/java/org/kohsuke/stapler/jelly/groovy/GroovyClassLoaderTearOffTest.java +++ b/groovy/src/test/java/org/kohsuke/stapler/jelly/groovy/GroovyClassLoaderTearOffTest.java @@ -54,7 +54,7 @@ public void testGettext() throws Exception { GroovyClassLoaderTearOff t = mcl.getTearOff(GroovyClassLoaderTearOff.class); Files.write(tmp, "output.write(_('localizable'))".getBytes(StandardCharsets.UTF_8)); - Files.write(tmp.resolveSibling(tmp.getFileName().toString().replaceFirst("[.]groovy$", ".properties")), "localizable=Localizable".getBytes(StandardCharsets.ISO_8859_1)); + Files.writeString(tmp.resolveSibling(tmp.getFileName().toString().replaceFirst("[.]groovy$", ".properties")), "localizable=Localizable", StandardCharsets.ISO_8859_1); JellyContext context = new JellyContext(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); diff --git a/jelly/src/main/java/org/kohsuke/stapler/jelly/AnnotationProcessorImpl.java b/jelly/src/main/java/org/kohsuke/stapler/jelly/AnnotationProcessorImpl.java index 041da2a55c..7357df8959 100644 --- a/jelly/src/main/java/org/kohsuke/stapler/jelly/AnnotationProcessorImpl.java +++ b/jelly/src/main/java/org/kohsuke/stapler/jelly/AnnotationProcessorImpl.java @@ -33,7 +33,6 @@ import javax.lang.model.util.ElementFilter; import javax.tools.Diagnostic.Kind; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -50,7 +49,7 @@ private static class MissingViews extends HashSet {} @Override public Set getSupportedAnnotationTypes() { - return Collections.singleton("*"); + return Set.of("*"); } @Override diff --git a/jelly/src/main/java/org/kohsuke/stapler/jelly/InternationalizedStringExpression.java b/jelly/src/main/java/org/kohsuke/stapler/jelly/InternationalizedStringExpression.java index 3e89704550..e2dc73b4ce 100644 --- a/jelly/src/main/java/org/kohsuke/stapler/jelly/InternationalizedStringExpression.java +++ b/jelly/src/main/java/org/kohsuke/stapler/jelly/InternationalizedStringExpression.java @@ -33,8 +33,6 @@ import java.util.List; import java.util.ArrayList; -import java.util.Collections; -import java.util.Arrays; /** * Expression of the form "%messageName(arg1,arg2,...)" that represents @@ -86,7 +84,7 @@ public InternationalizedStringExpression(ResourceBundle resourceBundle, String t } public List getArguments() { - return Collections.unmodifiableList(Arrays.asList(arguments)); + return List.of(arguments); } /** diff --git a/jelly/src/main/java/org/kohsuke/stapler/jelly/JellyFacet.java b/jelly/src/main/java/org/kohsuke/stapler/jelly/JellyFacet.java index 8e97303b4f..eac5ce8f76 100644 --- a/jelly/src/main/java/org/kohsuke/stapler/jelly/JellyFacet.java +++ b/jelly/src/main/java/org/kohsuke/stapler/jelly/JellyFacet.java @@ -41,7 +41,6 @@ import javax.servlet.ServletException; import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.logging.Level; @@ -131,7 +130,7 @@ public static void setExpressionFactory( ServletContextEvent event, ExpressionFa @SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "Legacy switch.") public static boolean TRACE = Boolean.getBoolean("stapler.jelly.trace"); - private static final Set> TEAROFF_TYPES = Collections.singleton(JellyClassTearOff.class); + private static final Set> TEAROFF_TYPES = Set.of(JellyClassTearOff.class); - private static final Set EXTENSION = Collections.singleton(".jelly"); + private static final Set EXTENSION = Set.of(".jelly"); }