From 21af155eeb24d0dc2964f412d1d7358f02821519 Mon Sep 17 00:00:00 2001 From: Louis Bergelson Date: Mon, 18 Dec 2023 16:12:30 -0500 Subject: [PATCH] Updating to java 21 * replacing use of deprecated function * making some methods final and Suppressing some 'this-escape' warnings * update github actions to use java 21 --- .github/workflows/tests.yml | 2 +- build.gradle | 5 +++-- .../barclay/argparser/ArgumentDefinition.java | 6 +++--- .../org/broadinstitute/barclay/argparser/ClassFinder.java | 3 ++- .../barclay/argparser/NamedArgumentDefinition.java | 1 + .../barclay/argparser/PositionalArgumentDefinition.java | 1 + .../java/org/broadinstitute/barclay/help/DocWorkUnit.java | 1 + 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b72fc2b..7ab8794 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ 17 ] + java: [ 21 ] experimental: [false] fail-fast: false continue-on-error: ${{ matrix.experimental }} diff --git a/build.gradle b/build.gradle index 471450a..51bc91d 100644 --- a/build.gradle +++ b/build.gradle @@ -11,8 +11,9 @@ wrapper { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } } group = 'org.broadinstitute' diff --git a/src/main/java/org/broadinstitute/barclay/argparser/ArgumentDefinition.java b/src/main/java/org/broadinstitute/barclay/argparser/ArgumentDefinition.java index c8e618d..1f9f6a7 100644 --- a/src/main/java/org/broadinstitute/barclay/argparser/ArgumentDefinition.java +++ b/src/main/java/org/broadinstitute/barclay/argparser/ArgumentDefinition.java @@ -53,7 +53,7 @@ public ArgumentDefinition(final Object containingObject, final Field underlyingF * Get the underlying {@code Field} for this argument * @return the {@code Field} for this argument */ - public Field getUnderlyingField() { return underlyingField; } + public final Field getUnderlyingField() { return underlyingField; } /** * Get the parent {@code Object} containing the {@code Field} for this argument. @@ -77,7 +77,7 @@ public ArgumentDefinition(final Object containingObject, final Field underlyingF * Get the {@code Object} representing the current value of the field for this object. * @return A boxed value even if the underlying field is a primitive. will not be null. */ - public Object getArgumentValue() { + public final Object getArgumentValue() { try { return getUnderlyingField().get(getContainingObject()); } catch (final IllegalAccessException e) { @@ -158,7 +158,7 @@ public List getOriginalCommandLineValues() { * constructors can be found. * @return {@code Class} for this field */ - protected Class getClassForUnderlyingField() { + protected final Class getClassForUnderlyingField() { final Field field = getUnderlyingField(); if (isCollectionField(field)) { final ParameterizedType clazz = (ParameterizedType) (field.getGenericType()); diff --git a/src/main/java/org/broadinstitute/barclay/argparser/ClassFinder.java b/src/main/java/org/broadinstitute/barclay/argparser/ClassFinder.java index e0ebd3c..c1a29eb 100644 --- a/src/main/java/org/broadinstitute/barclay/argparser/ClassFinder.java +++ b/src/main/java/org/broadinstitute/barclay/argparser/ClassFinder.java @@ -10,6 +10,7 @@ import java.net.URLClassLoader; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; import java.util.Enumeration; import java.util.LinkedHashSet; import java.util.Set; @@ -44,7 +45,7 @@ public ClassFinder(final File jarFile) throws IOException { // but the jarPath is remembered so that the iteration over the classpath skips anything other than // the jarPath. jarPath = jarFile.getCanonicalPath(); - final URL[] urls = {new URL("file", "", jarPath)}; + final URL[] urls = {Paths.get(jarPath).toUri().toURL()}; loader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); } diff --git a/src/main/java/org/broadinstitute/barclay/argparser/NamedArgumentDefinition.java b/src/main/java/org/broadinstitute/barclay/argparser/NamedArgumentDefinition.java index 9b6e5d1..804dcfc 100644 --- a/src/main/java/org/broadinstitute/barclay/argparser/NamedArgumentDefinition.java +++ b/src/main/java/org/broadinstitute/barclay/argparser/NamedArgumentDefinition.java @@ -42,6 +42,7 @@ public class NamedArgumentDefinition extends ArgumentDefinition { * {@code CommandLinePluginDescriptor} itself are not contained in a plugin, * and will not have a {@code descriptorForControllingPlugin}. can be null. */ + @SuppressWarnings("this-escape") public NamedArgumentDefinition( final Argument argumentAnnotation, final Object containingObject, diff --git a/src/main/java/org/broadinstitute/barclay/argparser/PositionalArgumentDefinition.java b/src/main/java/org/broadinstitute/barclay/argparser/PositionalArgumentDefinition.java index f93ebad..ba6890f 100644 --- a/src/main/java/org/broadinstitute/barclay/argparser/PositionalArgumentDefinition.java +++ b/src/main/java/org/broadinstitute/barclay/argparser/PositionalArgumentDefinition.java @@ -22,6 +22,7 @@ public class PositionalArgumentDefinition extends ArgumentDefinition { * @param containingObject the parent {@code Object} containing this argument. cannot be null. * @param argField the {@code Field} for this argument. cannot be null. */ + @SuppressWarnings("this-escape") public PositionalArgumentDefinition( final PositionalArguments positionalArgumentsAnnotation, final Object containingObject, diff --git a/src/main/java/org/broadinstitute/barclay/help/DocWorkUnit.java b/src/main/java/org/broadinstitute/barclay/help/DocWorkUnit.java index 2eb57d1..37a0f8e 100644 --- a/src/main/java/org/broadinstitute/barclay/help/DocWorkUnit.java +++ b/src/main/java/org/broadinstitute/barclay/help/DocWorkUnit.java @@ -48,6 +48,7 @@ public class DocWorkUnit implements Comparable { * @param clazz * @param documentedFeatureAnnotation */ + @SuppressWarnings("this-escape") public DocWorkUnit( final DocWorkUnitHandler workUnitHandler, final Element docElement,