From c6c6930bac3b265cf335167e0631f8e41025a04a Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Fri, 17 May 2024 14:37:36 -0400 Subject: [PATCH] tmf: Fix stream orElse(null) errors It seems that filter(Objects::nonNull) now changes the stream type to a <@NonNull E>, so that orElse(null) is no longer allowed. Change to check the optional presence before returning null. This change requires an upgrade to Tycho 4.0.9. Signed-off-by: Patrick Tasse --- .../os/linux/core/execution/graph/OsWorker.java | 6 +++--- .../profiling/core/model/CompositeHostModel.java | 13 +++++++------ pom.xml | 4 ++-- .../core/proxy/TmfRemoteConnectionFactory.java | 9 +++++---- .../tmf/ui/project/model/TmfExperimentFolder.java | 7 ++++--- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java index 00aeb517bc..799da90b8e 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 École Polytechnique de Montréal + * Copyright (c) 2015, 2024 École Polytechnique de Montréal and others * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License 2.0 which @@ -96,8 +96,8 @@ public String getHostId() { return Collections.emptyMap(); } ImmutableMap.Builder workerInfo = new Builder<>(); - workerInfo.put(OsStrings.tid(), String.valueOf(tid)); //$NON-NLS-1$ - Optional<@Nullable KernelAnalysisModule> kam = TmfTraceManager.getInstance().getActiveTraceSet() + workerInfo.put(OsStrings.tid(), String.valueOf(tid)); + Optional<@NonNull KernelAnalysisModule> kam = TmfTraceManager.getInstance().getActiveTraceSet() .stream() .filter(trace -> trace.getHostId().equals(getHostId())) .map(trace -> TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID)) diff --git a/analysis/org.eclipse.tracecompass.analysis.profiling.core/src/org/eclipse/tracecompass/internal/analysis/profiling/core/model/CompositeHostModel.java b/analysis/org.eclipse.tracecompass.analysis.profiling.core/src/org/eclipse/tracecompass/internal/analysis/profiling/core/model/CompositeHostModel.java index c28faf4bc0..dc1c0b517a 100644 --- a/analysis/org.eclipse.tracecompass.analysis.profiling.core/src/org/eclipse/tracecompass/internal/analysis/profiling/core/model/CompositeHostModel.java +++ b/analysis/org.eclipse.tracecompass.analysis.profiling.core/src/org/eclipse/tracecompass/internal/analysis/profiling/core/model/CompositeHostModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 École Polytechnique de Montréal + * Copyright (c) 2016, 2024 École Polytechnique de Montréal and others * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License 2.0 which @@ -114,19 +114,20 @@ public Collection getSamplingData(int tid, long start, long @Override public int getProcessId(int tid, long t) { - Integer pid = fKernelModules.stream() + Optional pid = fKernelModules.stream() .map(module -> KernelThreadInformationProvider.getProcessId(module, tid, t)) .filter(Objects::nonNull) - .findFirst().orElse(null); - return pid == null ? IHostModel.UNKNOWN_TID : (int) pid; + .findFirst(); + return pid.isEmpty() ? IHostModel.UNKNOWN_TID : pid.get(); } @Override public @Nullable String getExecName(int tid, long t) { - return fKernelModules.stream() + Optional execName = fKernelModules.stream() .map(module -> KernelThreadInformationProvider.getExecutableName(module, tid)) .filter(Objects::nonNull) - .findFirst().orElse(null); + .findFirst(); + return execName.isPresent() ? execName.get() : null; } /** diff --git a/pom.xml b/pom.xml index ecd43fe285..faf1d3a88f 100644 --- a/pom.xml +++ b/pom.xml @@ -52,8 +52,8 @@ false false - 4.0.3 - 4.0.3 + 4.0.9 + 4.0.9 true scm:git:https://github.com/eclipse-tracecompass/org.eclipse.tracecompass 1.4.2 diff --git a/tmf/org.eclipse.tracecompass.tmf.remote.core/src/org/eclipse/tracecompass/tmf/remote/core/proxy/TmfRemoteConnectionFactory.java b/tmf/org.eclipse.tracecompass.tmf.remote.core/src/org/eclipse/tracecompass/tmf/remote/core/proxy/TmfRemoteConnectionFactory.java index 644bfa3480..a3d4231849 100644 --- a/tmf/org.eclipse.tracecompass.tmf.remote.core/src/org/eclipse/tracecompass/tmf/remote/core/proxy/TmfRemoteConnectionFactory.java +++ b/tmf/org.eclipse.tracecompass.tmf.remote.core/src/org/eclipse/tracecompass/tmf/remote/core/proxy/TmfRemoteConnectionFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Ericsson + * Copyright (c) 2015, 2024 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License 2.0 which @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Optional; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -228,12 +229,12 @@ private static IRemoteConnectionType getConnectionType(URI hostUri) throws Remot if (manager == null) { return null; } - return manager.getAllRemoteConnections().stream() + Optional remoteConnection = manager.getAllRemoteConnections().stream() .filter(Objects::nonNull) .filter(connection -> connection.getName().equals(name)) .filter(connection -> connection.getConnectionType().getId().equals(remoteServicesId)) - .findFirst() - .orElse(null); + .findFirst(); + return remoteConnection.isPresent() ? remoteConnection.get() : null; } /** diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfExperimentFolder.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfExperimentFolder.java index 439fd2f3ca..5b55b7d1ce 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfExperimentFolder.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfExperimentFolder.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; @@ -189,11 +190,11 @@ public List getExperiments() { * @since 2.0 */ public @Nullable TmfExperimentElement getExperiment(@NonNull String name) { - return getExperiments().stream() + Optional<@NonNull TmfExperimentElement> exp = getExperiments().stream() .filter(Objects::nonNull) .filter(experiment -> experiment.getName().equals(name)) - .findFirst() - .orElse(null); + .findFirst(); + return exp.isPresent() ? exp.get() : null; }