-
-
Notifications
You must be signed in to change notification settings - Fork 548
fix: resolve memory leak in ChallengeConfig and adjust JDK 22 build c… #2467
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: master
Are you sure you want to change the base?
Changes from 1 commit
2b69ccb
4ca4035
36de8ce
6380d71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.function.Supplier; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.commons.io.FilenameUtils; | ||
|
|
@@ -40,12 +42,18 @@ public StringToChallengeNameConverter nameConverter() { | |
| return new StringToChallengeNameConverter(); | ||
| } | ||
|
|
||
| private record TextWithFileLocationConverter(TemplateGenerator templateGenerator) | ||
| private static final class TextWithFileLocationConverter | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not really necessary nested records are implicitly static, basically the same.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the feedback, @nbaars! You're absolutely right that nested records are implicitly static. I refactored the record to a static final class primarily to implement the thread-safe memoization pattern using a ConcurrentHashMap to resolve the memory leak identified in #389. Since records are intended for immutable data and don't allow additional instance fields, the class structure felt more appropriate for maintaining the cache state. Would you prefer I revert it to a record and try to handle the caching differently (e.g., using a static cache if appropriate), or is this class structure acceptable given the optimization goal? |
||
| implements Converter<String, TextWithFileLocation> { | ||
| private final TemplateGenerator templateGenerator; | ||
| private final Map<String, Supplier<String>> cache = new ConcurrentHashMap<>(); | ||
|
|
||
| public TextWithFileLocationConverter(TemplateGenerator templateGenerator) { | ||
| this.templateGenerator = templateGenerator; | ||
| } | ||
|
|
||
| @Override | ||
| public TextWithFileLocation convert(String source) { | ||
| return new TextWithFileLocation(source, read(source)); | ||
| return new TextWithFileLocation(source, cache.computeIfAbsent(source, this::read)); | ||
| } | ||
|
|
||
| private Supplier<String> read(String name) { | ||
|
|
@@ -78,7 +86,7 @@ public Challenges challenges( | |
| .filter(challenge -> challenge instanceof Challenge8) | ||
| .findFirst() | ||
| .get() | ||
| .spoiler(); // need early init to log the secret for debugging ;-). | ||
| .spoiler(); | ||
| return new Challenges(challengeDefinitions, challenges); | ||
| } | ||
| } | ||
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.
Hi @hemasree1516 thank you for your PR! Question: why do we downgrade to Java 22?
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.
Hi @commjoen , thank you for the feedback! I originally adjusted the version to 22 to resolve some MojoExecutionException issues I encountered in my local Windows environment while testing.
However, I understand the project standard is Java 25. I have just pushed a commit to revert the pom.xml to version 25 while keeping the memory leak fix for #389. Please let me know if the CI passes now or if further adjustments are needed.