8000 Nullability and data flow inspection fixes by kevinherron · Pull Request #1169 · eclipse-milo/milo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Nullability and data flow inspection fixes #1169

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

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,7 +10,6 @@

package org.eclipse.milo.examples.client;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
Expand All @@ -26,6 +25,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNullElse;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;

public class BrowseExample implements ClientExample {
Expand Down Expand Up @@ -61,7 +61,8 @@ private void browseNode(String indent, OpcUaClient client, NodeId browseRoot) {
try {
BrowseResult browseResult = client.browse(browse);

List<ReferenceDescription> references = List.of(browseResult.getReferences());
ReferenceDescription[] references =
requireNonNullElse(browseResult.getReferences(), new ReferenceDescription[0]);

for (ReferenceDescription rd : references) {
logger.info("{} Node={}", indent, rd.getBrowseName().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult;
import org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadRawModifiedDetails;
import org.eclipse.milo.opcua.stack.core.util.Lists;

import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;

Expand Down Expand Up @@ -79,7 +80,7 @@ public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throw
client.getStaticEncodingContext()
);

List<DataValue> dataValues = List.of(historyData.getDataValues());
List<DataValue> dataValues = Lists.ofNullable(historyData.getDataValues());

dataValues.forEach(v -> System.out.println("value=" + v));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,6 +23,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;

public class MethodExample implements ClientExample {

public static void main(String[] args) throws Exception {
Expand Down F438 Expand Up @@ -60,16 +63,18 @@ private CompletableFuture<Double> sqrt(OpcUaClient client, Double input) {

CompletableFuture<CallMethodResult> future =
client.callAsync(List.of(request))
.thenApply(r -> r.getResults()[0]);
.thenApply(r -> requireNonNull(r.getResults())[0]);

return future.thenCompose(result -> {
StatusCode statusCode = result.getStatusCode();

if (statusCode.isGood()) {
Double value = (Double) result.getOutputArguments()[0].getValue();
Double value = (Double) requireNonNull(result.getOutputArguments())[0].getValue();
return CompletableFuture.completedFuture(value);
} else {
StatusCode[] inputArgumentResults = result.getInputArgumentResults();
StatusCode[] inputArgumentResults =
requireNonNullElse(result.getInputArgumentResults(), new StatusCode[0]);

for (int i = 0; i < inputArgumentResults.length; i++) {
logger.error("inputArgumentResults[{}]={}", i, inputArgumentResults[i]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,6 +23,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

public class ReadExample implements ClientExample {

public static void main(String[] args) throws Exception {
Expand All @@ -48,7 +50,7 @@ public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throw
DataValue v0 = values.get(0);
DataValue v1 = values.get(1);

logger.info("State={}", ServerState.from((Integer) v0.getValue().getValue()));
logger.info("State={}", ServerState.from((Integer) requireNonNull(v0.getValue().getValue())));
logger.info("CurrentTime={}", v1.getValue().getValue());

future.complete(client);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -22,9 +22,12 @@
import org.eclipse.milo.opcua.stack.core.types.structured.RelativePath;
import org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement;
import org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse;
import org.eclipse.milo.opcua.stack.core.util.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

public class TranslateBrowsePathExample implements ClientExample {

public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -63,11 +66,12 @@ public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throw
})
)));

BrowsePathResult result = List.of(response.getResults()).get(0);
BrowsePathResult result = requireNonNull(response.getResults())[0];
StatusCode statusCode = result.getStatusCode();
logger.info("Status={}", statusCode);

List.of(result.getTargets()).forEach(target -> logger.info("TargetId={}", target.getTargetId()));
Lists.ofNullable(result.getTargets())
.forEach(target -> logger.info("TargetId={}", target.getTargetId()));

future.complete(client);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -32,6 +32,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

/**
* An example that shows reading the value of a node whose DataType is a custom structure type.
* <p>
Expand Down Expand Up @@ -103,7 +105,7 @@ private void readWriteCarExtras(OpcUaClient client) throws Exception {
DynamicOptionSet value = (DynamicOptionSet) readValue(client, nodeId);
logger.info("CarExtras: {}", value);

byte b = value.getValue().bytes()[0];
byte b = requireNonNull(value.getValue().bytes())[0];
value.setValue(ByteString.of(new byte[]{(byte) ~b}));

StatusCode status = writeValue(client, nodeId, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -20,6 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

public class SqrtMethod extends AbstractMethodInvocationHandler {

public static final Argument X = new Argument(
Expand Down Expand Up @@ -58,7 +60,7 @@ public Argument[] getOutputArguments() {
protected Variant[] invoke(InvocationContext invocationContext, Variant[] inputValues) {
logger.debug("Invoking sqrt() method of objectId={}", invocationContext.getObjectId());

double x = (double) inputValues[0].getValue();
double x = (double) requireNonNull(inputValues[0].getValue());
double xSqrt = Math.sqrt(x);

return new Variant[]{Variant.ofDouble(xSqrt)};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -75,6 +75,7 @@
import org.slf4j.LoggerFactory;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNullElse;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;

public class BinaryDataTypeDictionaryManager implements Lifecycle {
Expand Down Expand Up @@ -386,7 +387,7 @@ private EnumeratedType createBsdEnumeratedType(EnumDescription description) {
enumeratedType.setName(name.getName());
enumeratedType.setLengthInBits(32);

for (EnumField field : definition.getFields()) {
for (EnumField field : requireNonNullElse(definition.getFields(), new EnumField[0])) {
EnumeratedValue enumeratedValue = new EnumeratedValue();
enumeratedValue.setName(field.getName());
enumeratedValue.setValue(field.getValue().intValue());
Expand Down Expand Up @@ -428,7 +429,7 @@ private StructuredType createBsdStructuredType(StructureDescription description)
LinkedHashMap<String, StructureField> allFields = new LinkedHashMap<>();

for (StructureDefinition d : definitions) {
for (StructureField f : d.getFields()) {
for (StructureField f : requireNonNullElse(d.getFields(), new StructureField[0])) {
allFields.put(f.getName(), f);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2023 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -27,7 +27,6 @@
import java.util.stream.Stream;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.io.ByteStreams;
import com.google.common.primitives.Ints;
import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -64,12 +63,14 @@
import org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader;
import org.eclipse.milo.opcua.stack.core.types.structured.ViewDescription;
import org.eclipse.milo.opcua.stack.core.util.FutureUtils;
import org.eclipse.milo.opcua.stack.core.util.Lists;
import org.eclipse.milo.opcua.stack.core.util.Namespaces;
import org.opcfoundation.opcua.binaryschema.StructuredType;
import org.opcfoundation.opcua.binaryschema.TypeDictionary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
import static org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture;
Expand Down Expand Up @@ -444,10 +445,10 @@ private CompletableFuture<List<String>> readDataTypeDescriptionValues(List<NodeI
.exceptionally(ex -> PARTITION_SIZE);

return getPartitionSize.thenCompose(partitionSize -> {
List<List<NodeId>> partitions = Lists.partition(nodeIds, partitionSize);
Stream<List<NodeId>> partitions = Lists.partition(nodeIds, partitionSize);

CompletableFuture<List<List<DataValue>>> sequence = FutureUtils.sequence(
partitions.stream().map(list -> {
partitions.map(list -> {
List<ReadValueId> readValueIds = list.stream()
.map(nodeId ->
new ReadValueId(
Expand Down Expand Up @@ -539,7 +540,7 @@ private CompletableFuture<List<ReferenceDescription>> browseNode(BrowseDescripti
return client.getTransport()
.sendRequestMessage(browseRequest)
.thenApply(BrowseResponse.class::cast)
.thenApply(r -> Objects.requireNonNull(r.getResults())[0])
.thenApply(r -> requireNonNull(r.getResults())[0])
.thenCompose(result -> {
List<ReferenceDescription> references =
Collections.synchronizedList(new ArrayList<>());
Expand Down Expand Up @@ -591,7 +592,7 @@ private CompletableFuture<List<ReferenceDescription>> browseNextAsync(
.sendRequestMessage(request)
.thenApply(BrowseNextResponse.class::cast)
.thenCompose(response -> {
BrowseResult result = List.of(response.getResults()).get(0);
BrowseResult result = requireNonNull(response.getResults())[0];

return maybeBrowseNext(result, references);
});
Expand All @@ -617,7 +618,7 @@ private CompletableFuture<List<DataValue>> readNodes(List<ReadValueId> readValue
return client.getTransport()
.sendRequestMessage(readRequest)
.thenApply(ReadResponse.class::cast)
.thenApply(r -> List.of(r.getResults()));
.thenApply(r -> org.eclipse.milo.opcua.stack.core.util.Lists.ofNullable(r.getResults()));
}

public static class TypeDictionaryInfo {
Expand Down
Loading
0