-
Notifications
You must be signed in to change notification settings - Fork 0
Replace assertions with typed exceptions and remove -ea requirement #43
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e568292
Initial plan
Copilot 3630d88
Add Severity enum, EditorException, and require* utility functions
Copilot 606b5e7
Replace assertions in Train.kt and SimpleTrack.kt
Copilot 2581de1
Replace assertions in AbstractPath.kt and RailSwitch.kt
Copilot 7692712
Replace assertion in RailSemaphore.kt
Copilot 5c95f8d
Replace assertions in cell classes and add comprehensive analysis
Copilot 79fc59c
Move exceptions to exceptions package and remove -ea requirement
Copilot b9ccdd5
Remove backup file from repository
Copilot ae799ed
Fix test import for TrackOperationException
Copilot 6844906
fix build and tests
bedaHovorka 09a8bbd
Remove EXCEPTION_HANDLING_ANALYSIS.md from repository
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
81 changes: 81 additions & 0 deletions
81
src/main/kotlin/cz/vutbr/fit/interlockSim/exceptions/EditorException.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* Brno University of Technology | ||
| * Faculty of Information Technology | ||
| * | ||
| * BSc Thesis 2006/2007 | ||
| * | ||
| * Railway Interlocking Simulator | ||
| * | ||
| * Bedrich Hovorka | ||
| */ | ||
| package cz.vutbr.fit.interlockSim.exceptions | ||
|
|
||
| /** | ||
| * Exception thrown during editor operations, validation, or user mistakes. | ||
| * Examples: wrong move, bad element placing, invalid configuration. | ||
| * | ||
| * @property severity Severity level of the exception | ||
| * @property obj Optional object associated with the exception | ||
| */ | ||
| class EditorException( | ||
| val severity: Severity, | ||
| message: String, | ||
| cause: Throwable?, | ||
| private val obj: Any? | ||
| ) : Exception(message, cause) { | ||
|
|
||
| /** | ||
| * Create EditorException with default FATAL severity | ||
| */ | ||
| constructor() : this(Severity.FATAL, "", null, null) | ||
|
|
||
| /** | ||
| * Create EditorException with default FATAL severity | ||
| * @param obj Object associated with the exception | ||
| */ | ||
| constructor(obj: Any?) : this(Severity.FATAL, "", null, obj) | ||
|
|
||
| /** | ||
| * Create EditorException with default FATAL severity | ||
| * @param message Error message | ||
| */ | ||
| constructor(message: String) : this(Severity.FATAL, message, null, null) | ||
|
|
||
| /** | ||
| * Create EditorException with specified severity | ||
| * @param severity Severity level | ||
| * @param message Error message | ||
| */ | ||
| constructor(severity: Severity, message: String) : this(severity, message, null, null) | ||
|
|
||
| /** | ||
| * Create EditorException with specified severity and object | ||
| * @param severity Severity level | ||
| * @param message Error message | ||
| * @param obj Object associated with the exception | ||
| */ | ||
| constructor(severity: Severity, message: String, obj: Any?) : this(severity, message, null, obj) | ||
|
|
||
| /** | ||
| * Create EditorException with default FATAL severity and cause | ||
| * @param cause Underlying cause | ||
| */ | ||
| constructor(cause: Throwable?) : this(Severity.FATAL, "", cause, null) | ||
|
|
||
| /** | ||
| * Create EditorException with specified severity and cause | ||
| * @param severity Severity level | ||
| * @param cause Underlying cause | ||
| * @param obj Object associated with the exception | ||
| */ | ||
| constructor(severity: Severity, cause: Throwable?, obj: Any?) : this(severity, "", cause, obj) | ||
|
|
||
| /** | ||
| * @return object getter | ||
| */ | ||
| fun getObject(): Any? = obj | ||
|
|
||
| override fun toString(): String { | ||
| val msg = message?.takeIf { it.isNotEmpty() } ?: "" | ||
| return "${this::class.simpleName}[$severity]: $msg" | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i hope, it's only main class, not for running test (remove -ea)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -ea flag has been removed from ALL tasks in build.gradle.kts:
applicationblock (line 118-120) - affects main class executiontasks.test(line 171) - unit tests no longer use -eaintegrationTesttask (line 225) - integration tests no longer use -earunSim,runEditor,runExample,runSimFromXml)Both main application AND tests now run without assertions enabled, as all critical validation is being replaced with explicit exception checks using the new require* functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot @claude tasks.test integrationTest - it's true guys?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude finished @bedaHovorka's task in 40s —— View job
Verifying -ea flag removal from test tasks
Verification Results ✅
YES, it's true! The
-eaflag has been completely removed from all test tasks inbuild.gradle.kts.Evidence:
Unit Tests (
tasks.test- lines 171-215):-eaflag presentjvmArgsconfiguration at all-eawas previously removed)Integration Tests (
integrationTest- lines 222-268):-eaflag presentjvmArgsconfiguration at all-eawas previously removed)Summary:
The copilot agent's claim is 100% accurate. Both test tasks now run without assertions enabled (
-ea), which aligns with the PR's goal of replacing assertions with explicit typed exceptions. The application no longer depends on the-eaJVM flag for correct operation.Files verified:
build.gradle.kts:171-215(unit tests)build.gradle.kts:222-268(integration tests)build.gradle.kts:118-120(main application)runSim,runEditor,runExample,runSimFromXml) - lines 403-466All confirmed: No
-eaflags anywhere in the build configuration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, confirmed. Both
tasks.testandintegrationTesthave had the-eaflag completely removed. I verified by searching the entire build.gradle.kts file - there are zero occurrences ofjvmArgs("-ea")in any test configuration. Tests now run without assertions enabled, relying on the new explicit exception-based validation instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@claude @claude :my question is, if it not needed for run of test plugins?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude finished @bedaHovorka's task in 1m 8s —— View job
Test Plugin Requirements Analysis ✅
Answer: NO, the
-eaflag is NOT needed for test plugins to function correctly.Technical Justification
1. JUnit 5 Does Not Require
-eafor OperationJUnit 5 (Jupiter) does not use Java assertions (
assertstatements) internally for its core functionality. The test framework uses:AssertionFailedError) when assertions failassertEquals(),assertTrue(), etc. don't depend on JVM assertion flags@Test,@BeforeEach, etc. work independently of-ea2. Current Test Configuration (Verified)
From
build.gradle.ktsanalysis:tasks.test, line 171): NO-eaflag, NOjvmArgsat allintegrationTest, line 222): NO-eaflag, NOjvmArgsat all3. CI/CD Evidence (Production Proof)
GitHub Actions workflow (
.github/workflows/gradle-java21.yml) shows:./gradlew test- runs without-ea./gradlew integrationTest- runs without-ea-eaflagRecent successful builds (from CI status):
Both builds ran ALL tests (unit + integration + smoke test) without
-eaflag and passed successfully.What Changed and Why It Works
Before this PR:
assertstatements for validation-eaflag to enable assertion checksAfter this PR (current state):
SimulationException,EditorException)require*utility functions that throw exceptions (always active)Example transformation:
Conclusion
The test plugins (JUnit 5, Mockito, AssertK) do not need
-eabecause:-eaYour test tasks are correctly configured. ✅