Skip to content

Replace assert with runtime checks in TcpMessageDecoder#1718

Merged
kevinherron merged 2 commits intofeature/reverse-connectfrom
copilot/sub-pr-1716-again
Mar 25, 2026
Merged

Replace assert with runtime checks in TcpMessageDecoder#1718
kevinherron merged 2 commits intofeature/reverse-connectfrom
copilot/sub-pr-1716-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

Java assertions are disabled by default in production JVMs, meaning invalid message types in TcpMessageDecoder were silently accepted rather than rejected. All four decode methods now throw UaException(Bad_TcpMessageTypeInvalid) when the message type or chunk type doesn't match expectations.

Changes

  • TcpMessageDecoder: Replaced assert in all four decode methods (decodeHello, decodeAcknowledge, decodeError, decodeReverseHello) with explicit runtime checks:
// Before
assert (messageType == MessageType.Hello && chunkType == 'F');

// After
if (messageType != MessageType.Hello || chunkType != 'F') {
    throw new UaException(
        StatusCodes.Bad_TcpMessageTypeInvalid,
        "unexpected MessageType/chunkType: " + messageType + "/" + chunkType);
}

This is consistent with how message type validation is handled elsewhere in the transport layer (e.g., UascServerHelloHandler, OpcTcpReverseConnectTransport).


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 25, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repo.eclipse.org
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.18-8/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.18-8/x64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.13/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.13/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.13 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.13/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/milo/milo org.codehaus.plexus.classworlds.launcher.Launcher -q spotless:apply -pl opc-ua-stack/stack-core (dns block)
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.18-8/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.18-8/x64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.13/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.13/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.13 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.13/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/milo/milo org.codehaus.plexus.classworlds.launcher.Launcher -q clean compile -pl opc-ua-stack/stack-core (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [WIP] Update Reverse Connect Support to address feedback on decode methods Replace assert with runtime checks in TcpMessageDecoder Mar 25, 2026
Copilot AI requested a review from kevinherron March 25, 2026 13:19
@kevinherron kevinherron marked this pull request as ready for review March 25, 2026 13:21
@kevinherron kevinherron merged commit 778977d into feature/reverse-connect Mar 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants