Skip to content

Commit

Permalink
tmf: Fix stream orElse(null) errors
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
PatrickTasse committed Oct 22, 2024
1 parent f76c638 commit c6c6930
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -96,8 +96,8 @@ public String getHostId() {
return Collections.emptyMap();
}
ImmutableMap.Builder<String, String> 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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -114,19 +114,20 @@ public Collection<AggregatedCallSite> getSamplingData(int tid, long start, long

@Override
public int getProcessId(int tid, long t) {
Integer pid = fKernelModules.stream()
Optional<Integer> 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<String> execName = fKernelModules.stream()
.map(module -> KernelThreadInformationProvider.getExecutableName(module, tid))
.filter(Objects::nonNull)
.findFirst().orElse(null);
.findFirst();
return execName.isPresent() ? execName.get() : null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
<skip-short-tc-ui-tests>false</skip-short-tc-ui-tests>
<skip-long-tc-ui-tests>false</skip-long-tc-ui-tests>

<tycho-version>4.0.3</tycho-version>
<tycho-extras-version>4.0.3</tycho-extras-version>
<tycho-version>4.0.9</tycho-version>
<tycho-extras-version>4.0.9</tycho-extras-version>
<tycho-use-project-settings>true</tycho-use-project-settings>
<tycho.scmUrl>scm:git:https://github.com/eclipse-tracecompass/org.eclipse.tracecompass</tycho.scmUrl>
<cbi-plugins.version>1.4.2</cbi-plugins.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -228,12 +229,12 @@ private static IRemoteConnectionType getConnectionType(URI hostUri) throws Remot
if (manager == null) {
return null;
}
return manager.getAllRemoteConnections().stream()
Optional<IRemoteConnection> 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -189,11 +190,11 @@ public List<TmfExperimentElement> 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;
}


Expand Down

0 comments on commit c6c6930

Please sign in to comment.