Skip to content

Commit

Permalink
build(deps): bump com.github.spotbugs:spotbugs-maven-plugin from 4.7.…
Browse files Browse the repository at this point in the history
…3.6 to 4.8.2.0 (#311)

* build(deps): bump com.github.spotbugs:spotbugs-maven-plugin

Bumps [com.github.spotbugs:spotbugs-maven-plugin](https://github.com/spotbugs/spotbugs-maven-plugin) from 4.7.3.6 to 4.8.2.0.
- [Release notes](https://github.com/spotbugs/spotbugs-maven-plugin/releases)
- [Commits](spotbugs/spotbugs-maven-plugin@spotbugs-maven-plugin-4.7.3.6...spotbugs-maven-plugin-4.8.2.0)

---
updated-dependencies:
- dependency-name: com.github.spotbugs:spotbugs-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* clean up constructor throws

* remove 'throws' declaration that never happens

* mitigate potential finalizer attack

* remove 'throws' declarations that never happen

* mitigate incomplete construction finalizer problem

* delay connection attempt and throws until call time

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Andrew Azores <aazores@redhat.com>
  • Loading branch information
dependabot[bot] and andrewazores committed Dec 20, 2023
1 parent cf0aac3 commit e52ac1e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 90 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<org.jsoup.version>1.16.1</org.jsoup.version>

<com.github.spotbugs.version>4.8.3</com.github.spotbugs.version>
<com.github.spotbugs.plugin.version>4.7.3.6</com.github.spotbugs.plugin.version>
<com.github.spotbugs.plugin.version>4.8.2.0</com.github.spotbugs.plugin.version>
<org.junit.jupiter.version>5.10.1</org.junit.jupiter.version>
<org.hamcrest.version>2.2</org.hamcrest.version>
<org.mockito.version>5.2.0</org.mockito.version>
Expand Down
53 changes: 19 additions & 34 deletions src/main/java/io/cryostat/core/EventOptionsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package io.cryostat.core;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import org.openjdk.jmc.common.unit.IConstrainedMap;
import org.openjdk.jmc.common.unit.IConstraint;
Expand All @@ -27,36 +27,26 @@
import org.openjdk.jmc.common.unit.QuantityConversionException;
import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID;
import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID;
import org.openjdk.jmc.rjmx.IConnectionHandle;
import org.openjdk.jmc.rjmx.ServiceNotAvailableException;
import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo;
import org.openjdk.jmc.rjmx.services.jfr.internal.FlightRecorderServiceV2;

import io.cryostat.core.net.JFRConnection;
import io.cryostat.core.tui.ClientWriter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class EventOptionsBuilder {

private final boolean isV2;
private final IMutableConstrainedMap<EventOptionID> map;
private Map<IEventTypeID, Map<String, IOptionDescriptor<?>>> knownTypes;
private Map<String, IEventTypeID> eventIds;

public EventOptionsBuilder(ClientWriter cw, JFRConnection connection, Supplier<Boolean> v2)
throws ServiceNotAvailableException, IOException,
org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException {
this.isV2 = v2.get();
this.map = connection.getService().getDefaultEventOptions().emptyWithSameConstraints();
knownTypes = new HashMap<>();
eventIds = new HashMap<>();
private final Map<IEventTypeID, Map<String, IOptionDescriptor<?>>> knownTypes;
private final Map<String, IEventTypeID> eventIds;

if (!isV2) {
cw.println("Flight Recorder V1 is not supported");
}
public EventOptionsBuilder(
IMutableConstrainedMap<EventOptionID> empty,
Collection<? extends IEventTypeInfo> eventTypes) {
this.map = empty.emptyWithSameConstraints();
this.knownTypes = new HashMap<>();
this.eventIds = new HashMap<>();

for (IEventTypeInfo eventTypeInfo : connection.getService().getAvailableEventTypes()) {
for (IEventTypeInfo eventTypeInfo : eventTypes) {
eventIds.put(
eventTypeInfo.getEventTypeID().getFullKey(), eventTypeInfo.getEventTypeID());
knownTypes.putIfAbsent(
Expand Down Expand Up @@ -87,12 +77,8 @@ static <T, V> V capture(T t) {
return (V) t;
}

@SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Field is never mutated")
public IConstrainedMap<EventOptionID> build() {
if (!isV2) {
return null;
}
return map;
return map.mutableCopy();
}

public static class EventTypeException extends Exception {
Expand All @@ -108,18 +94,17 @@ public static class EventOptionException extends Exception {
}

public static class Factory {
private final ClientWriter cw;

public Factory(ClientWriter cw) {
this.cw = cw;
}

public EventOptionsBuilder create(JFRConnection connection)
throws IOException, ServiceNotAvailableException,
org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException {
IConnectionHandle handle = connection.getHandle();
return new EventOptionsBuilder(
cw, connection, () -> FlightRecorderServiceV2.isAvailable(handle));
if (!FlightRecorderServiceV2.isAvailable(connection.getHandle())) {
throw new UnsupportedOperationException("Only FlightRecorder V2 is supported");
}
IMutableConstrainedMap<EventOptionID> empty =
connection.getService().getDefaultEventOptions().emptyWithSameConstraints();
Collection<? extends IEventTypeInfo> eventTypes =
connection.getService().getAvailableEventTypes();
return new EventOptionsBuilder(empty, eventTypes);
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/io/cryostat/core/agent/AgentJMXHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import javax.management.ObjectName;
import javax.management.ReflectionException;

import org.openjdk.jmc.rjmx.ConnectionException;
import org.openjdk.jmc.rjmx.IConnectionHandle;

public class AgentJMXHelper {
Expand All @@ -41,7 +40,7 @@ public class AgentJMXHelper {
private final IConnectionHandle connectionHandle;
private final MBeanServerConnection mbsc;

public AgentJMXHelper(IConnectionHandle connectionHandle) throws ConnectionException {
public AgentJMXHelper(IConnectionHandle connectionHandle) {
this.connectionHandle = connectionHandle;
mbsc = connectionHandle.getServiceOrDummy(MBeanServerConnection.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public LocalProbeTemplateService(FileSystem fs, Environment env) throws IOExcept
}
}

protected final void finalize() {}

public ProbeTemplate addTemplate(InputStream inputStream, String filename)
throws FileAlreadyExistsException, IOException, SAXException {
Path path = fs.pathOf(env.getEnv(TEMPLATE_PATH), filename);
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/io/cryostat/core/net/JFRJMXConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public class JFRJMXConnection implements JFRConnection {
FileSystem fs,
Environment env,
IConnectionDescriptor cd,
List<Runnable> listeners)
throws ConnectionException {
List<Runnable> listeners) {
this.cw = cw;
this.fs = fs;
this.env = env;
Expand All @@ -87,8 +86,7 @@ public class JFRJMXConnection implements JFRConnection {
this.serviceFactory = new FlightRecorderServiceFactory();
}

JFRJMXConnection(ClientWriter cw, FileSystem fs, Environment env, IConnectionDescriptor cd)
throws ConnectionException {
JFRJMXConnection(ClientWriter cw, FileSystem fs, Environment env, IConnectionDescriptor cd) {
this(cw, fs, env, cd, List.of());
}

Expand All @@ -108,7 +106,7 @@ public synchronized IConnectionHandle getHandle() throws ConnectionException, IO

public synchronized CryostatFlightRecorderService getService()
throws ConnectionException, IOException, ServiceNotAvailableException {
return new JmxFlightRecorderService(this, cw);
return new JmxFlightRecorderService(this);
}

public TemplateService getTemplateService() {
Expand Down
Loading

0 comments on commit e52ac1e

Please sign in to comment.