Skip to content

Further Java Modernization#1863

Merged
kingthorin merged 8 commits into
datafaker-net:mainfrom
kingthorin:java-updts-1
Jul 1, 2026
Merged

Further Java Modernization#1863
kingthorin merged 8 commits into
datafaker-net:mainfrom
kingthorin:java-updts-1

Conversation

@kingthorin

Copy link
Copy Markdown
Collaborator
  • collect(Collectors.toList()) ➡️ toList()
  • Use List/Set/Map.of where immutables are okay
  • Leverage Records
  • Use updated instanceof form to reduce assignments/intermediate storage
  • Leverage var + local variable type inference
  • Use text blocks to avoid concatenation, etc.

Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Types inferred at compile time; no runtime performance impact when var replaces an equivalent explicit type.

Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
@codecov-commenter

codecov-commenter commented Jun 28, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 88.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.55%. Comparing base (1d0ae3f) to head (72d1738).

Files with missing lines Patch % Lines
.../java/net/datafaker/service/FakeValuesService.java 75.00% 1 Missing and 4 partials ⚠️
...java/net/datafaker/service/FakeValuesGrouping.java 80.00% 0 Missing and 1 partial ⚠️
...tafaker/transformations/JavaObjectTransformer.java 87.50% 0 Missing and 1 partial ⚠️
...net/datafaker/transformations/JsonTransformer.java 88.88% 0 Missing and 1 partial ⚠️
.../net/datafaker/transformations/XmlTransformer.java 80.00% 0 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1863      +/-   ##
============================================
+ Coverage     92.48%   92.55%   +0.06%     
- Complexity     3561     3565       +4     
============================================
  Files           346      346              
  Lines          7050     7048       -2     
  Branches        684      685       +1     
============================================
+ Hits           6520     6523       +3     
+ Misses          366      364       -2     
+ Partials        164      161       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/main/java/net/datafaker/service/files/EnFile.java Outdated
Comment thread src/main/java/net/datafaker/service/FakeValuesContext.java Outdated
@kingthorin kingthorin changed the title Further Java 17 Modernization Further Java Modernization Jun 28, 2026

StringJoiner data = new StringJoiner(LINE_SEPARATOR);
for (IN in : input) {
for (var in : input) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

one symbol longer?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Either way it's dealt with at compile time not runtime.

if (consumer == null) {
final Field<Object, ?>[] fields = schema.getFields();
final Map<String, java.lang.reflect.Field> name2ClassField = Stream.of(clazz.getDeclaredFields()).collect(
var name2ClassField = Stream.of(clazz.getDeclaredFields()).collect(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

before that the var was final, after that is not...
not sure we should make such change

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I'll check and revert those.

Comment on lines +14 to +17
public static String linesTrimTrailing(String textBlock) {
String result = lines(textBlock);
String sep = System.lineSeparator();
return result.endsWith(sep) ? result.substring(0, result.length() - sep.length()) : result;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This might be dangerous especially for SQL containing \n inside values

INSERT INTO "MyTable" ("N\nu\nm\nb\ne\nr\n", "Password") VALUES (1, '5');

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay, will revert.

@asolntsev

Copy link
Copy Markdown
Collaborator

@kingthorin While I generally like records, I must warn that after conversion a class to a recorder, all fields become publicly accessible.

E.g. in class FakeValuesContext, fields singletonLocale, filenameHashCode, path, urlHashCode didn't have a public getter. Now they all have public getters. Users might start using them, though we didn't plan it.

Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
@kingthorin

kingthorin commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

@asolntsev & @snuyanzin got your comments all addressed I believe.

@kingthorin kingthorin merged commit 9da71f3 into datafaker-net:main Jul 1, 2026
17 checks passed
@kingthorin kingthorin deleted the java-updts-1 branch July 1, 2026 16:13
@asolntsev asolntsev added this to the 3.0.0 milestone Jul 3, 2026
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.

4 participants