Repository navigation
Accept primitive arrays in AttributeWriter's DataType check - #2118
Merged
kevinherron merged 1 commit intoOct 12, 2026
Merged
Conversation
Variant holds primitive arrays such as int[] and double[], for example from Variant.ofInt32Array, and the binary encoder writes them. A write of one through AttributeWriter still failed with Bad_TypeMismatch: validateDataType took the array's component class, int.class, and DataTypeTree.isAssignable only knows boxed backing classes such as Integer. Two writes hit this. Server code that writes a primitive array through AttributeWriter was rejected. A client Write with an IndexRange into a Variable whose stored value is a primitive array was rejected too: the decoded update is boxed, but NumericRange merges it into a copy of the stored array, which keeps the primitive form. Whole-value client Writes were not affected, because the decoder always produces boxed arrays. The check now uses the boxed component type, so a primitive array is accepted wherever its boxed form is.
kevinherron
added this pull request to stack #2124
October 12, 2026 15:28
This was referenced Oct 12, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 of 6 (#2118 to #2123) of a stack of server performance changes, found by profiling the Milo server in the o6-automation/opcua-benchmarks suite. This one is a correctness fix that the rest of the stack does not depend on; it is at the bottom because it is the smallest and safest.
Problem
Variantholds primitive arrays such asint[]anddouble[], for example fromVariant.ofInt32Array(int[]), and the binary encoder writes them. A write of one throughAttributeWriterstill failed withBad_TypeMismatch.AttributeWriter.validateDataTypetook the array's component class,int.classfor anint[], and askedDataTypeTree.isAssignablewhether it fits the Variable's DataType. The tree only knows boxed backing classes such asInteger, so the answer was always no.Two writes hit this:
AttributeWriter, for exampleVariant.ofDoubleArray(new double[] {1, 2})into a Double array Variable.Double[], butNumericRange.writeToValueAtRangemerges it into a copy of the stored array, which keeps the primitivedouble[]form, and the merged value failed the check.Whole-value client Writes were not affected, because the binary decoder always produces boxed arrays.
Change
validateDataTypenow usesArrayUtil.getBoxedType, so a primitive array is accepted wherever its boxed form is. Boxed arrays, scalars, and Matrix values with boxed elements are checked exactly as before.Tests
New cases in
AttributeWriterTest(integration-tests):writePrimitiveArrayToVariableOfMatchingDataType: adouble[]written to a Double array Variable is accepted and stored asdouble[].writePrimitiveMatrixToVariableOfMatchingDataType: a Matrix ofint[][]written to an Int32 rank-2 Variable is accepted and stored.indexRangeWriteIntoStoredPrimitiveArrayUpdatesTheElement: a client Write ofDouble[] {9}at IndexRange"1"into a storeddouble[] {1, 2, 3}succeeds and storesdouble[] {1, 9, 3}.rejectPrimitiveArrayOfAnotherDataType(control): anint[]written to a Double Variable is still rejected.On the unfixed base, the three positive tests fail with
Bad_TypeMismatch.Not changed
An IndexRange write whose update has the wrong element type, such as
double[]into anint[], is reported asBad_IndexRangeNoDatainstead ofBad_TypeMismatch, becauseNumericRange.writeToValueAtRangewraps every failure inBad_IndexRangeNoData. That behavior predates this PR and is unchanged here.Verification
mvn -q -pl opc-ua-sdk/integration-tests -am test -Dtest=AttributeWriterTest: 45 tests pass.mvn -q -pl opc-ua-sdk/integration-tests -am verify): 451 test classes, 5,792 tests, no failures, 4 skipped.