-
-
Notifications
You must be signed in to change notification settings - Fork 459
Improvements config.serial bundle: Add JavaDoc & fix concurrency bug #5161
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
base: main
Are you sure you want to change the base?
Conversation
b29d419 to
c2116d9
Compare
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.
Pull request overview
This PR adds comprehensive JavaDoc documentation to several core bundles and fixes a concurrency bug in the serial configuration provider. The improvements enhance code maintainability and address thread-safety issues in dynamic OSGi service binding.
- Added JavaDoc to methods in 6 files across multiple bundles
- Fixed concurrency issue by synchronizing USB discovery service add/remove methods
- Added defensive null check for directory file listing in ConfigDispatcher
- Added @NonNullByDefault annotation to ConfigDispatcher class
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| bundles/org.openhab.core.id/src/main/java/org/openhab/core/id/internal/UUIDResource.java | Added JavaDoc for REST endpoint method that retrieves instance UUID |
| bundles/org.openhab.core.id/src/main/java/org/openhab/core/id/InstanceUUID.java | Added JavaDoc for private helper methods that generate and read UUID files |
| bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java | Added comprehensive JavaDoc for constructor, configuration methods, and holiday calculation utilities |
| bundles/org.openhab.core.config.serial/src/main/java/org/openhab/core/config/serial/internal/SerialConfigOptionProvider.java | Added JavaDoc, synchronized discovery add/remove methods to fix concurrency bug, and added defensive filter for null/empty serial port names |
| bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcher.java | Added JavaDoc for activation, deactivation, and watch event processing methods |
| bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java | Added JavaDoc for activation and configuration processing methods, added @NonNullByDefault annotation, and added null check for directory listing |
Comments suppressed due to low confidence (1)
bundles/org.openhab.core.config.serial/src/main/java/org/openhab/core/config/serial/internal/SerialConfigOptionProvider.java:156
- Potential race condition: The
getParameterOptionsmethod reads frompreviouslyDiscoveredwithout synchronization, whileremoveUsbSerialDiscovery(line 98) can clear this collection. AlthoughCopyOnWriteArraySetis thread-safe for individual operations, ifremoveUsbSerialDiscoveryis called concurrently withgetParameterOptions, the returned parameter options may be inconsistent with the current state of registered discovery services.
Consider either:
- Making
getParameterOptionssynchronized to matchaddUsbSerialDiscoveryandremoveUsbSerialDiscovery, or - Using a local snapshot of
previouslyDiscoveredat the start of the method if you want to avoid holding the lock during stream processing.
Example:
@Override
public synchronized @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
// ... existing implementation
} @Override
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
if (SERIAL_PORT.equals(context)) {
return Stream
.concat(serialPortManager.getIdentifiers().map(SerialPortIdentifier::getName),
previouslyDiscovered.stream().map(UsbSerialDeviceInformation::getSerialPort))
.filter(serialPortName -> serialPortName != null && !serialPortName.isEmpty()) //
.distinct() //
.map(serialPortName -> new ParameterOption(serialPortName, serialPortName)) //
.toList();
}
return null;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Reads the first line from the UUID file. | ||
| * This method opens the file, reads the first line, and properly closes the reader. | ||
| * If the file cannot be read or is empty, an empty string is returned and a warning is logged. | ||
| * | ||
| * @param file the file to read from | ||
| * @return the first line of the file, or an empty string if the file cannot be read or is empty | ||
| */ |
Copilot
AI
Dec 1, 2025
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 JavaDoc is partially inaccurate. The statement "a warning is logged" only applies when the file cannot be read (IOException). When the file is empty or contains a null first line, an empty string is returned but no warning is logged.
Consider updating to:
/**
* Reads the first line from the UUID file.
* This method opens the file, reads the first line, and properly closes the reader.
* If the file cannot be read, a warning is logged. An empty string is returned if
* the file cannot be read or is empty.
*
* @param file the file to read from
* @return the first line of the file, or an empty string if the file cannot be read or is empty
*/
...onfig.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java
Show resolved
Hide resolved
bundles/org.openhab.core.id/src/main/java/org/openhab/core/id/internal/UUIDResource.java
Show resolved
Hide resolved
88ade9c to
5dac315
Compare
Signed-off-by: Vambot07 <[email protected]>
…NonNullByDefault Signed-off-by: Vambot07 <[email protected]>
Signed-off-by: Vambot07 <[email protected]>
Signed-off-by: Vambot07 <[email protected]>
Signed-off-by: Vambot07 <[email protected]>
Signed-off-by: Vambot07 <[email protected]>
5dac315 to
70be4af
Compare
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.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java:161
gson.fromJson()can returnnullif the JSON is null or cannot be parsed into the target type. This would cause a null pointer exception on line 161 when callinginitializeProcessPIDMapping(). Add a null check after line 160 before callinginitializeProcessPIDMapping().
exclusivePIDMap = gson.fromJson(reader, ExclusivePIDMap.class);
exclusivePIDMap.initializeProcessPIDMapping();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * This method is called after processing configuration files to ensure the state is preserved | ||
| * across component restarts. | ||
| */ | ||
| private void storeCurrentExclusivePIDList() { |
Copilot
AI
Dec 2, 2025
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 field exclusivePIDStore is marked as @Nullable (line 126) but is dereferenced here without a null check. Add a null check before using this field, or ensure it cannot be null at this point.
| private void storeCurrentExclusivePIDList() { | |
| private void storeCurrentExclusivePIDList() { | |
| if (exclusivePIDStore == null) { | |
| logger.error("Cannot store exclusive PID list: exclusivePIDStore is null."); | |
| return; | |
| } |
| */ | ||
| private void storeCurrentExclusivePIDList() { | ||
| try (FileWriter writer = new FileWriter(exclusivePIDStore)) { | ||
| exclusivePIDMap.setCurrentExclusivePIDList(); |
Copilot
AI
Dec 2, 2025
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 field exclusivePIDMap is marked as @Nullable (line 122) but is dereferenced here without a null check. While the finally block in loadExclusivePIDList() ensures it's initialized, add a null check or assertion to make this explicit and prevent potential null pointer exceptions.
| * <p> | ||
| * This method is called during component activation to restore the state from previous runs. | ||
| */ | ||
| private void loadExclusivePIDList() { |
Copilot
AI
Dec 2, 2025
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 field exclusivePIDStore is marked as @Nullable (line 126) but is dereferenced here without a null check. While activate() initializes this field, the method call sequence in activate() (line 143-144) means loadExclusivePIDList() could theoretically be called with a null exclusivePIDStore. Consider adding a null check or using Objects.requireNonNull() to ensure the field is initialized before use.
| private void loadExclusivePIDList() { | |
| private void loadExclusivePIDList() { | |
| if (exclusivePIDStore == null) { | |
| logger.error("Exclusive PID store file is not initialized. Skipping loading exclusive PID list."); | |
| exclusivePIDMap = new ExclusivePIDMap(); | |
| return; | |
| } |
Signed-off-by: Vambot07 <[email protected]>
Added JavaDoc documentation to 5 files in console.rfc147 bundle: - CommandWrapper.java: 2 methods (constructor, _main) - ConsoleCommandsContainer.java: 1 interface method - ConsoleSupportRfc147.java: 7 methods (constructor, activate, deactivate, add/remove, createProperties) - OSGiConsole.java: 2 methods (constructor, getBase) - HelpConsoleCommandExtension.java: 3 methods (constructor, setConsoleCommandsContainer, help) Total: 15 methods documented Build: SUCCESS with only pre-existing warnings Signed-off-by: Vambot07 <[email protected]>
No description provided.