diff --git a/build.gradle b/build.gradle index cc95ca83783..6fbe07535eb 100644 --- a/build.gradle +++ b/build.gradle @@ -750,7 +750,7 @@ class JDKDetails { url += "_${arch}" } println "Retrieving JDK from catalog..." - def catalogMetadataUrl = new URL(url) + def catalogMetadataUrl = URI.create(url).toURL() def catalogConnection = catalogMetadataUrl.openConnection() catalogConnection.requestMethod = 'GET' assert catalogConnection.responseCode == 200 diff --git a/logstash-core/lib/logstash/instrument/periodic_poller/jvm.rb b/logstash-core/lib/logstash/instrument/periodic_poller/jvm.rb index 13d4db7053f..7b347cb831c 100644 --- a/logstash-core/lib/logstash/instrument/periodic_poller/jvm.rb +++ b/logstash-core/lib/logstash/instrument/periodic_poller/jvm.rb @@ -36,7 +36,7 @@ module LogStash module Instrument module PeriodicPoller class JVM < Base class GarbageCollectorName YOUNG_GC_NAMES = Set.new(["Copy", "PS Scavenge", "ParNew", "G1 Young Generation", "scavenge", "GPGC New"]) - OLD_GC_NAMES = Set.new(["MarkSweepCompact", "PS MarkSweep", "ConcurrentMarkSweep", "G1 Old Generation", "global", "GPGC Old"]) + OLD_GC_NAMES = Set.new(["MarkSweepCompact", "PS MarkSweep", "ConcurrentMarkSweep", "G1 Old Generation", "G1 Concurrent GC", "global", "GPGC Old"]) YOUNG = :young OLD = :old diff --git a/logstash-core/src/main/java/org/logstash/common/SourceWithMetadata.java b/logstash-core/src/main/java/org/logstash/common/SourceWithMetadata.java index 1063dfd5830..0448a8140ea 100644 --- a/logstash-core/src/main/java/org/logstash/common/SourceWithMetadata.java +++ b/logstash-core/src/main/java/org/logstash/common/SourceWithMetadata.java @@ -65,6 +65,7 @@ public String getText() { private static final Pattern emptyString = Pattern.compile("^\\s*$"); + @SuppressWarnings("this-escape") public SourceWithMetadata(String protocol, String id, Integer line, Integer column, String text, String metadata) throws IncompleteSourceWithMetadataException { this.protocol = protocol; this.id = id; @@ -73,6 +74,9 @@ public SourceWithMetadata(String protocol, String id, Integer line, Integer colu this.text = text; this.metadata = metadata; + // This is the reason why of the "this-escape" suppress warning, a method (attributes) is invoked on + // a non completely initialized object and that could generate some errors in accessing fields. + // This is not the case because the method is private and not overridable in sub classes. List badAttributes = this.attributes().stream().filter(a -> { if (a == null) return true; if (a instanceof String) { diff --git a/logstash-core/src/main/java/org/logstash/config/ir/expression/RegexValueExpression.java b/logstash-core/src/main/java/org/logstash/config/ir/expression/RegexValueExpression.java index 6c1437ab2ef..3dd7889fc5c 100644 --- a/logstash-core/src/main/java/org/logstash/config/ir/expression/RegexValueExpression.java +++ b/logstash-core/src/main/java/org/logstash/config/ir/expression/RegexValueExpression.java @@ -34,7 +34,7 @@ public RegexValueExpression(SourceWithMetadata meta, Object value) throws Invali throw new InvalidIRException("Regex value expressions can only take strings!"); } - this.regex = getSource(); + this.regex = (String) value; } @Override diff --git a/logstash-core/src/main/java/org/logstash/config/ir/graph/Edge.java b/logstash-core/src/main/java/org/logstash/config/ir/graph/Edge.java index 4d5c17c6308..f72e7891e98 100644 --- a/logstash-core/src/main/java/org/logstash/config/ir/graph/Edge.java +++ b/logstash-core/src/main/java/org/logstash/config/ir/graph/Edge.java @@ -33,6 +33,7 @@ public abstract class Edge implements SourceComponent { private Graph graph; + @SuppressWarnings("this-escape") protected Edge(Vertex from, Vertex to) throws InvalidIRException { this.from = from; this.to = to; @@ -41,6 +42,9 @@ protected Edge(Vertex from, Vertex to) throws InvalidIRException { throw new InvalidIRException("Cannot create a cyclic vertex! " + to); } + // This is the reason why of the "this-escape" suppress warning. The instance is passed to the method acceptsOutgoingEdge + // before the constructor completes, so could potentially reach some runtime errors due to fields not initialized. + // This is not the case because actually that method just does type check on reference. if (!this.from.acceptsOutgoingEdge(this)) { throw new Vertex.InvalidEdgeTypeException(String.format("Invalid outgoing edge %s for edge %s", this.from, this)); } diff --git a/logstash-core/src/main/java/org/logstash/execution/PipelineReporterExt.java b/logstash-core/src/main/java/org/logstash/execution/PipelineReporterExt.java index 7c455253ec2..6ddc3eda5c3 100644 --- a/logstash-core/src/main/java/org/logstash/execution/PipelineReporterExt.java +++ b/logstash-core/src/main/java/org/logstash/execution/PipelineReporterExt.java @@ -157,7 +157,7 @@ public RubyHash toHash(final ThreadContext context) { return result; } - @SuppressWarnings({"unchecked","rawtypes"}) + @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) private RubyArray workerStates(final ThreadContext context, final RubyHash batchMap) { final RubyArray result = context.runtime.newArray(); ((Iterable) pipeline.callMethod(context, "worker_threads")) @@ -174,6 +174,7 @@ private RubyArray workerStates(final ThreadContext context, final RubyHash batch IRubyObject batchSize = Optional.of((RubyThread) thread) .map(RubyThread::getNativeThread) + // JTODO getId has been deprecated in JDK 19, when JDK 21 is the target version use threadId() instead .map(Thread::getId) .map(id -> batchMap.op_aref(context, context.runtime.newFixnum(id))) .map(batch -> extractBatchSize(context, batch)) diff --git a/logstash-core/src/main/java/org/logstash/execution/QueueReadClientBase.java b/logstash-core/src/main/java/org/logstash/execution/QueueReadClientBase.java index d227adc8bd5..535cd838a0e 100644 --- a/logstash-core/src/main/java/org/logstash/execution/QueueReadClientBase.java +++ b/logstash-core/src/main/java/org/logstash/execution/QueueReadClientBase.java @@ -128,8 +128,10 @@ public IRubyObject rubyReadBatch(final ThreadContext context) throws Interrupted } @Override + @SuppressWarnings("deprecation") public void closeBatch(QueueBatch batch) throws IOException { batch.close(); + // JTODO getId has been deprecated in JDK 19, when JDK 21 is the target version use threadId() instead inflightBatches.remove(Thread.currentThread().getId()); } @@ -186,7 +188,9 @@ public void rubyAddOutputMetrics(final IRubyObject size) { } @Override + @SuppressWarnings("deprecation") public void startMetrics(QueueBatch batch) { + // JTODO getId has been deprecated in JDK 19, when JDK 21 is the target version use threadId() instead long threadId = Thread.currentThread().getId(); inflightBatches.put(threadId, batch); } diff --git a/logstash-core/src/main/java/org/logstash/instrument/monitors/HotThreadsMonitor.java b/logstash-core/src/main/java/org/logstash/instrument/monitors/HotThreadsMonitor.java index 0406d319597..e16aed00d7e 100644 --- a/logstash-core/src/main/java/org/logstash/instrument/monitors/HotThreadsMonitor.java +++ b/logstash-core/src/main/java/org/logstash/instrument/monitors/HotThreadsMonitor.java @@ -145,6 +145,7 @@ public static List detect() { * stacktrace_size - max depth of stack trace * @return A list of ThreadReport including all selected threads */ + @SuppressWarnings("deprecation") public static List detect(Map options) { String type = "cpu"; if (options.containsKey(ORDERED_BY)) { @@ -164,6 +165,7 @@ public static List detect(Map options) { Map reports = new HashMap<>(); for (long threadId : threadMXBean.getAllThreadIds()) { + // JTODO getId has been deprecated in JDK 19, when JDK 21 is the target version use threadId() instead if (Thread.currentThread().getId() == threadId) { continue; } diff --git a/logstash-core/src/main/java/org/logstash/plugins/inputs/Stdin.java b/logstash-core/src/main/java/org/logstash/plugins/inputs/Stdin.java index 5b2808a1919..017f36754b9 100644 --- a/logstash-core/src/main/java/org/logstash/plugins/inputs/Stdin.java +++ b/logstash-core/src/main/java/org/logstash/plugins/inputs/Stdin.java @@ -75,7 +75,10 @@ public Stdin(final String id, final Configuration configuration, final Context c this(id, configuration, context, new FileInputStream(FileDescriptor.in).getChannel()); } + @SuppressWarnings("this-escape") Stdin(final String id, final Configuration configuration, final Context context, FileChannel inputChannel) { + // This is the reason why of the "this-escape" suppress warning, but this is used just to grab the class + // for the logger. logger = context.getLogger(this); this.id = id; try { diff --git a/logstash-core/src/main/java/org/logstash/util/UtilExt.java b/logstash-core/src/main/java/org/logstash/util/UtilExt.java index bba64002486..41b3825a4d0 100644 --- a/logstash-core/src/main/java/org/logstash/util/UtilExt.java +++ b/logstash-core/src/main/java/org/logstash/util/UtilExt.java @@ -34,6 +34,7 @@ public class UtilExt { @JRubyMethod(module = true) + @SuppressWarnings("deprecation") public static IRubyObject get_thread_id(final ThreadContext context, IRubyObject self, IRubyObject thread) { if (!(thread instanceof RubyThread)) { throw context.runtime.newTypeError(thread, context.runtime.getThread()); @@ -41,6 +42,7 @@ public static IRubyObject get_thread_id(final ThreadContext context, IRubyObject final Thread javaThread = ((RubyThread) thread).getNativeThread(); // weak-reference // even if thread is dead the RubyThread instance might stick around while the Java thread // instance already could have been garbage collected - let's return nil for dead meat : + // JTODO getId has been deprecated in JDK 19, when JDK 21 is the target version use threadId() instead return javaThread == null ? context.nil : context.runtime.newFixnum(javaThread.getId()); } diff --git a/logstash-core/src/test/java/org/logstash/ext/JrubyMemoryReadClientExtTest.java b/logstash-core/src/test/java/org/logstash/ext/JrubyMemoryReadClientExtTest.java index 0af4dfdcd39..dff3c4845a3 100644 --- a/logstash-core/src/test/java/org/logstash/ext/JrubyMemoryReadClientExtTest.java +++ b/logstash-core/src/test/java/org/logstash/ext/JrubyMemoryReadClientExtTest.java @@ -38,6 +38,7 @@ public final class JrubyMemoryReadClientExtTest extends RubyTestBase { @Test + @SuppressWarnings("deprecation") public void testInflightBatchesTracking() throws InterruptedException, IOException { final BlockingQueue queue = new ArrayBlockingQueue<>(10); @@ -47,6 +48,7 @@ public void testInflightBatchesTracking() throws InterruptedException, IOExcepti final QueueBatch batch = client.readBatch(); final RubyHash inflight = client.rubyGetInflightBatches(context); assertThat(inflight.size(), is(1)); + // JTODO getId has been deprecated in JDK 19, when JDK 21 is the target version use threadId() instead assertThat(inflight.get(Thread.currentThread().getId()), is(batch)); client.closeBatch(batch); assertThat(client.rubyGetInflightBatches(context).size(), is(0)); diff --git a/logstash-core/src/test/java/org/logstash/log/TestingDeprecationPlugin.java b/logstash-core/src/test/java/org/logstash/log/TestingDeprecationPlugin.java index ee84b3b966d..cdaa85a9dfe 100644 --- a/logstash-core/src/test/java/org/logstash/log/TestingDeprecationPlugin.java +++ b/logstash-core/src/test/java/org/logstash/log/TestingDeprecationPlugin.java @@ -40,6 +40,7 @@ public class TestingDeprecationPlugin implements Codec { * @param configuration Logstash Configuration * @param context Logstash Context */ + @SuppressWarnings("this-escape") public TestingDeprecationPlugin(final Configuration configuration, final Context context) { deprecationLogger = context.getDeprecationLogger(this); } diff --git a/logstash-core/src/test/java/org/logstash/plugins/AliasRegistryTest.java b/logstash-core/src/test/java/org/logstash/plugins/AliasRegistryTest.java index 4ad12ed0060..2387bbb7c7b 100644 --- a/logstash-core/src/test/java/org/logstash/plugins/AliasRegistryTest.java +++ b/logstash-core/src/test/java/org/logstash/plugins/AliasRegistryTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Map; @@ -34,7 +35,7 @@ public void testProductionConfigAliasesGemsExists() throws IOException { for (AliasRegistry.PluginCoordinate alias : aliasesDefinitions.keySet()) { final String gemName = alias.fullName(); - URL url = new URL("https://rubygems.org/api/v1/gems/" + gemName +".json"); + URL url = URI.create("https://rubygems.org/api/v1/gems/" + gemName +".json").toURL(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "application/json"); diff --git a/logstash-core/src/test/java/org/logstash/secret/store/SecretStoreFactoryTest.java b/logstash-core/src/test/java/org/logstash/secret/store/SecretStoreFactoryTest.java index ab9f6ea3c7b..9a6129375bc 100644 --- a/logstash-core/src/test/java/org/logstash/secret/store/SecretStoreFactoryTest.java +++ b/logstash-core/src/test/java/org/logstash/secret/store/SecretStoreFactoryTest.java @@ -157,6 +157,7 @@ public static class MemoryStore implements SecretStore { Map secrets = new HashMap(1); + @SuppressWarnings("this-escape") public MemoryStore() { persistSecret(LOGSTASH_MARKER, LOGSTASH_MARKER.getKey().getBytes(StandardCharsets.UTF_8)); }