Skip to content

Lab 2: fix code smells and bugs (no behavior change)#19

Open
nik-bykoff wants to merge 2 commits intolenagrin:masterfrom
nik-bykoff:lab-02-code-smells
Open

Lab 2: fix code smells and bugs (no behavior change)#19
nik-bykoff wants to merge 2 commits intolenagrin:masterfrom
nik-bykoff:lab-02-code-smells

Conversation

@nik-bykoff
Copy link
Copy Markdown

Summary

Address 5-10 Sonar-style smells/bugs in NetSdrClientApp without changing the public behavior. Compiler warnings inside the production project drop from 5 to 0 (overall solution: 18 -> 15; remaining 15 belong to EchoTcpServer and NuGet vulnerabilities, scheduled for Labs 6/7).

Bug-class fixes

  • Rename NetSdrClient.Disconect -> Disconnect and update both Program.cs and the test suite.
  • Remove a stray ; before var iqDataMode = (byte)0x80; in StartIQAsync.
  • Make responseTaskSource thread-safe by replacing the racy null-check pattern with Interlocked.Exchange and TrySetResult.
  • Replace Enumerable.Aggregate((l, r) => $\"{l} {r}\") (which throws on empty input) with string.Join(\" \", ...) in three log statements.
  • Rewrite NetSdrMessageHelper.GetSamples from an O(n^2) IEnumerable.Count/Skip loop into an O(n) for loop with a reusable byte[4] buffer.
  • Replace UdpClientWrapper.GetHashCode MD5 implementation with HashCode.Combine and add a matching Equals(object?) override.

Code-smell fixes

  • Drop unused using static System.Runtime.InteropServices.JavaScript.JSType; from two files.
  • Mark TcpClientWrapper._host/_port as readonly.
  • Make TcpClientWrapper._cts nullable to remove CS8625.
  • Drop unused exception variable names from cancellation handlers.

Intentionally deferred

  • Duplicate StopListening/Exit in UdpClientWrapper is left intact for Lab 4 (Duplications).
  • EchoTcpServer warnings are deferred to Lab 6 (testability refactor).
  • NuGet vulnerability warnings (Newtonsoft.Json 13.0.0, SharpZipLib 1.3.2) are deferred to Lab 7.

Test plan

  • dotnet build NetSdrClient.sln -c Release --no-restore succeeds.
  • dotnet test NetSdrClient.sln -c Release --no-build reports 8/8 passing.
  • After SonarCloud is wired (PR Lab 1: SonarCloud + GitHub Actions CI bootstrap #18), New Bugs = 0 and New Code Smells substantially decrease in this PR.

Discipline / Author

  • Subject: Реінжиніринг програмного забезпечення
  • Student: Биков Нікіта Вячеславович, group ПЗС-1

nik-bykoff added 2 commits May 4, 2026 21:31
- Move SONAR_PROJECT_KEY/SONAR_ORGANIZATION into workflow env block with explicit setup instructions for fork-based usage.

- Update README with student header, fork/upstream links and a table of all eight lab reports.

- Replace SonarCloud badges with placeholders for nik-bykoff fork.

- Add docs/labs/lab-01.md report describing manual SonarCloud steps, CI workflow layout and verification checklist.

- Ignore local .env files to prevent accidental token leaks.
- Rename NetSdrClient.Disconect to Disconnect (typo) and update callers/tests.

- Remove stray semicolon in StartIQAsync and unused JSType using-statics.

- Make responseTaskSource thread-safe via Interlocked.Exchange + TrySetResult.

- Replace Aggregate-on-empty-may-throw log formatting with string.Join in three places.

- Rewrite GetSamples from O(n^2) IEnumerable.Count loop to O(n) for-loop with reusable byte[4] buffer.

- Replace MD5-based UdpClientWrapper.GetHashCode with HashCode.Combine and add Equals override.

- Make TcpClientWrapper._cts nullable, mark _host/_port readonly, drop unused exception variable names.

- All eight existing unit tests still pass; compiler warnings dropped from 18 to 15 (rest are EchoTcpServer or NuGet).
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.

1 participant