Skip to content

Conversation

TranceLove
Copy link
Collaborator

Description

Add guard against invalid Integers as port number passed into NetCopyConnectionInfo.

Issue tracker

Fixes #4362

Automatic tests

  • Added test cases

Manual tests

  • Done

Build tasks success

Successfully running following tasks on local:

  • ./gradlew assembledebug
  • ./gradlew spotlessCheck

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

VishnuSanal
VishnuSanal previously approved these changes Apr 14, 2025
@VishnuSanal VishnuSanal added the PR-Awaiting-Final-Review this PR is awaiting a final review/approval label Apr 14, 2025
it[7].toInt()
} else {
LOGGER.warn("Port number is out of range: ${it[7]}")
0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this return the default port for ssh? I would think that returning 0 would just crash whatever uses this value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this to be the responsibility of downstream code - here is for just the regex extraction magic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. The type looks like it doesn't have any error state. port: Int should probably be port: Int? and be set to null on these cases, so that users know that the port could be "broken/unset".

}
} catch (e: NumberFormatException) {
LOGGER.warn("Unable to parse port number: ${it[7]}", e)
0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. It should be downstream code's responsibility of determining the default port number of different protocols.

@EmmanuelMess EmmanuelMess added PR-Requested-Changes this PR is awaiting an update from the author and removed PR-Awaiting-Final-Review this PR is awaiting a final review/approval labels May 1, 2025
@VishalNehra VishalNehra merged commit fec8c68 into release/4.0 May 26, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Requested-Changes this PR is awaiting an update from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NumberFormatException on NetCopyConnectionInfo#init
4 participants