Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK 21 move #15719

Merged
merged 12 commits into from
Apr 3, 2024
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/bootstrap/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
# specific language governing permissions and limitations
# under the License.

# The following line is needed because from starting from JDK 21 LinkedHashSet
# has a package private map method that JRuby bound as a usable method.
# It's mainly related to Gradle opening java.base module and this interfere with
# JRuby binding of methods. Full description at https://github.com/jruby/jruby/issues/8061#issuecomment-1908807511
java.util.LinkedHashSet.remove_method(:map) rescue nil
andsel marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually now that main and 8.13 are on JRuby 9.4.6.0 we should be able to remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsvd yep, good spot :-) removed with 1f5f735 and it's green.
Ready for a quick review


require_relative "environment"
LogStash::Bundler.setup!({:without => [:build]})
require "logstash-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Object> badAttributes = this.attributes().stream().filter(a -> {
if (a == null) return true;
if (a instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRubyObject>) pipeline.callMethod(context, "worker_threads"))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public static List<ThreadReport> detect() {
* stacktrace_size - max depth of stack trace
* @return A list of ThreadReport including all selected threads
*/
@SuppressWarnings("deprecation")
public static List<ThreadReport> detect(Map<String, String> options) {
String type = "cpu";
if (options.containsKey(ORDERED_BY)) {
Expand All @@ -164,6 +165,7 @@ public static List<ThreadReport> detect(Map<String, String> options) {
Map<Long, ThreadReport> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions logstash-core/src/main/java/org/logstash/util/UtilExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
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());
}
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public final class JrubyMemoryReadClientExtTest extends RubyTestBase {

@Test
@SuppressWarnings("deprecation")
public void testInflightBatchesTracking() throws InterruptedException, IOException {
final BlockingQueue<JrubyEventExtLibrary.RubyEvent> queue =
new ArrayBlockingQueue<>(10);
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public static class MemoryStore implements SecretStore {

Map<SecretIdentifier, ByteBuffer> secrets = new HashMap(1);

@SuppressWarnings("this-escape")
public MemoryStore() {
persistSecret(LOGSTASH_MARKER, LOGSTASH_MARKER.getKey().getBytes(StandardCharsets.UTF_8));
}
Expand Down