Trunk 6497 - Fix NPE for Integration Test Failures running on mysql or postgresql #5584
+93
−17
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.
Problem - When running tests with -DuseInMemoryDatabase=false, many tests fail with NullPointerException at line 341 in getRuntimeProperties().
Error Pattern:
[ERROR] DrugOrderValidatorTest.:53->BaseContextSensitiveTest.:208 >BaseContextSensitiveTest.getRuntimeProperties:341 » NullPointer
Root Cause
In both BaseContextSensitiveTest classes (JUnit 4 and JUnit 5), but this error comes from Junit 5 when useInMemoryDatabase=false: The code reads system properties (databaseUrl, databaseUsername, databasePassword, databaseDriver, databaseDialect) that may be null. These null values are passed directly to runtimeProperties.setProperty(). Later access to these properties causes NullPointerException.
The issue occurs because:
Containers.ensureDatabaseRunning() may not have set the system properties yet, or The properties weren't set manually, or There was a failure in the container initialization.
Solution
Suggested Entire Fix
The NPE is resolved by validation, but the root cause remains: missing system properties (databaseUrl, databaseUsername, databasePassword, databaseDriver, databaseDialect) when useInMemoryDatabase=false.
To fully fix the error, we must ensure those properties are set before tests start—either by letting Containers.ensureDatabaseRunning() set them, or by passing them explicitly on the Maven command line.
If using MySQL, swap the driver/dialect and URL accordingly.
If Containers.ensureDatabaseRunning() is supposed to set these automatically, we should verify why it isn’t running or isn’t able to set them in the current environment (e.g., missing -Ddatabase flag, Testcontainers disabled, or network/permission issues).