Fix #341: Add model classes for java.util.logging#583
Conversation
- Created Logger, LogManager, and Level model classes - Bypasses native method calls and complex JDK initialization - Adds test case to verify Logger.getLogger() works in JPF
|
Hi @cyrille-artho, |
cyrille-artho
left a comment
There was a problem hiding this comment.
Thank you for your contribution.
Please remove changes in whitespace in FileHandler, as there is no code change there.
Also, please try to add a minimal Handler for the log output so we can "write" the log to an array instead of to the terminal. This avoids cluttering the output during testing and lets us compare the output to the expected result.
| * Apache License, Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0. |
There was a problem hiding this comment.
Please avoid changes in whitespace, as we subsequently want to merge changes to master to other branches (to support newer Java versions). Therefore, we want to keep only essential changes.
| @Test | ||
| public void testGetLogger() { | ||
| if (verifyNoPropertyViolation()) { | ||
| System.out.println("--- calling getLogger"); |
There was a problem hiding this comment.
remove println in unit tests
| } | ||
|
|
||
| public void log(Level level, String msg) { | ||
| System.out.println("[" + level.getName() + "] " + name + ": " + msg); |
There was a problem hiding this comment.
We probably want to define the Handler in the logger, too, so we can redirect the log to an OutputStream. For testing, we can redirect to a ByteArrayOutputStream to compare the "written" messages to that stream with an expected result.
There was a problem hiding this comment.
A very lightweight Handler will suffice for us; the only functionality that is essential is that the messages do not get written to the terminal during testing.
| System.out.println("--- calling getLogger"); | ||
| Logger log = Logger.getLogger("testLogger"); | ||
| assertNotNull(log); | ||
| System.out.println("--- success: " + log.getName()); |
There was a problem hiding this comment.
Change this statement to an assertion (e.g., assertEquals(log.getName(), "testLogger") and add a few assertions to check other log settings.
| if (verifyNoPropertyViolation()) { | ||
| System.out.println("--- calling getLogger"); | ||
| Logger log = Logger.getLogger("testLogger"); | ||
| assertNotNull(log); |
There was a problem hiding this comment.
You can remove this line, as log is used below, so the test would fail if log were null.
There was a problem hiding this comment.
Thank you for the detailed review!
I will address all the points:
- Reverting the whitespace changes in FileHandler.java.
- Removing the System.out.println calls in the test.
- Implementing a minimal
HandlerandLogRecordmodel so we can redirect output to a stream. - Updating the test to verify log content using assertions instead of visual inspection.
Working on the updates now!
|
Thank you for your changes. |
|
@cyrille-artho Following your advice, I have closed this Pull Request and opened a fresh one to ensure a clean commit history and to remove the unrelated files (like ClockTest and FileHandler) that were accidentally included here. |
Problem
JPF crashes when code calls
Logger.getLogger()because the real JDK implementation uses:jdk.internal.misc.VM.initializeFromArchive)Solution
Created model classes for
java.util.logging.Logger,LogManager, andLevelthat provide simplified, JPF-compatible implementations.Changes
src/classes/modules/java.logging/java/util/logging/Logger.java- Model class for Loggersrc/classes/modules/java.logging/java/util/logging/LogManager.java- Model class for LogManagersrc/classes/modules/java.logging/java/util/logging/Level.java- Model class for Levelsrc/tests/gov/nasa/jpf/test/java/util/LoggerTest.java- Test caseTesting
All existing tests pass + new test confirms
Logger.getLogger()works without crashes.