8000 feat: adopt Java 21–25 language features (closes #160) by kawasima · Pull Request #161 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content

feat: adopt Java 21–25 language features (closes #160) - #161

Merged
kawasima merged 2 commits into
developfrom
feat/java25-language-features
Apr 4, 2026
Merged

kawasima merged 2 commits into
developfrom
feat/java25-language-features

Conversation

@kawasima
@kawasima kawasima commented Apr 4, 2026
Copy link
Copy Markdown
Collaborator

Summary

  • Replace ~13 unused catch-block variables with _ (Java 22 unnamed variables) across enkan-core, enkan-web, enkan-system, and enkan-devel
  • Remove ThreadLocal<MessageDigest> from ETagUtils; create a new MessageDigest per call — avoids ThreadLocal pitfalls under virtual threads (Java 21)
  • Declare middlewareStack in WebApplication as List and funcQueue in ThreadingUtils as SequencedCollection to use the Java 21 abstraction
  • Apply text block to UndertowComponent.toString() (Java 15)

Test plan

  • mvn test -B -DexcludedGroups=integration — BUILD SUCCESS, 0 failures

Closes #160

🤖 Generated with Claude Code

- Replace unused catch variables with unnamed _ (Java 22) across 13 sites
- Remove ThreadLocal<MessageDigest> from ETagUtils; create per-call instance
  to avoid ThreadLocal pitfalls under virtual threads (Java 21)
- Declare middlewareStack as List and funcQueue as SequencedCollection
  to use SequencedCollection abstraction (Java 21)
- Apply text block to UndertowComponent.toString() (Java 15)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI left a comment
Copy link
Copy Markdown

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 modernizes Enkan’s Java codebase to better align with Java 21–25 language/library features, with a focus on clearer intent (unnamed catch variables), safer behavior under virtual threads, and use of newer collection abstractions.

Changes:

  • Replaced unused catch-block exception variables with Java 22’s unnamed variable (_) across multiple modules.
  • Updated ETagUtils to avoid ThreadLocal<MessageDigest> by creating a new MessageDigest per call (virtual-thread-friendly).
  • Adopted Java 21 collection abstractions (List/SequencedCollection) and converted UndertowComponent.toString() to a text block.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
enkan-web/src/main/java/enkan/web/util/HttpRequestUtils.java Uses unnamed catch variable for ignored NumberFormatException.
enkan-web/src/main/java/enkan/web/util/ETagUtils.java Removes ThreadLocal<MessageDigest>; creates SHA-256 digest per call and updates Javadoc.
enkan-web/src/main/java/enkan/web/util/CodecUtils.java Uses unnamed catch variables where exceptions are intentionally ignored.
enkan-web/src/main/java/enkan/web/middleware/negotiation/AcceptHeaderNegotiator.java Uses unnamed catch variables for ignored UnsupportedCharsetException.
enkan-web/src/main/java/enkan/web/middleware/multipart/TempfilePart.java Uses unnamed catch variable for ignored IOException on close.
enkan-web/src/main/java/enkan/web/middleware/IdleSessionTimeoutMiddleware.java Uses unnamed catch variable for ignored NumberFormatException.
enkan-web/src/main/java/enkan/web/application/WebApplication.java Declares middlewareStack using List (Java 21+ sequenced APIs).
enkan-system/src/main/java/enkan/system/command/StartCommand.java Uses unnamed catch variable for ignored IOException.
enkan-devel/src/main/java/enkan/system/devel/ClassWatcher.java Uses unnamed catch variable for InterruptedException in watcher loop.
enkan-core/src/main/java/enkan/util/ThreadingUtils.java Uses SequencedCollection for ordered queue behavior.
enkan-core/src/main/java/enkan/exception/MisconfigurationException.java Uses unnamed catch variables for ignored IOException during resource loading.
enkan-core/src/main/java/enkan/collection/Parameters.java Uses unnamed catch variables for ignored NumberFormatException.
enkan-component-undertow/src/main/java/enkan/component/undertow/UndertowComponent.java Converts toString() to a text block with formatted(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

key = watchService.poll(10, TimeUnit.SECONDS);
if (key == null) continue;
} catch (InterruptedException ex) {
} catch (InterruptedException _) {
Copilot AI Apr 4, 2026
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The InterruptedException catch exits without restoring the thread's interrupted status. Since poll(...) clears the interrupt flag when throwing, returning here can cause callers/shutdown logic to miss the interruption signal. Set the interrupt status again (Thread.currentThread().interrupt()) before returning (or break and let the outer loop observe it).

Suggested change
} catch (InterruptedException _) {
} catch (InterruptedException _) {
Thread.currentThread().interrupt();

Copilot uses AI. Check for mistakes.
Comment on lines +95 to +100
return """
#UndertowComponent {
"host": "%s",
"port": "%s",
"dependencies": "%s"
}""".formatted(getHost(), getPort(), dependenciesToString());
Copilot AI Apr 4, 2026
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text block will include a leading newline (because the opening """ is followed by a line break). That changes UndertowComponent.toString() to start with whitespace/newline, which can be surprising in logs/debug output. Consider placing the first character immediately after the opening delimiter (or otherwise trimming/stripIndent-ing) to preserve the previous single-line start.

Copilot uses AI. Check for mistakes.
- ClassWatcher: restore interrupted flag after catching InterruptedException
- UndertowComponent: strip leading newline from text block via stripLeading()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kawasima
kawasima merged commit 32b9daa into develop Apr 4, 2026
1 check passed
@kawasima
kawasima deleted the feat/java25-language-features branch April 4, 2026 11:30
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.

2 participants

0