Skip to content
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

Add limits overriding with system properties #112

Merged
merged 5 commits into from
Apr 28, 2024

Conversation

Obolrom
Copy link
Contributor

@Obolrom Obolrom commented Apr 23, 2024

This PR relates to Issue: #104

Proposed Changes

  • Override MAX_FIELD_SIZE and MAX_FIELD_COUNT with system properties

@osiegmar
Copy link
Owner

Thanks for contributing to FastCSV! Please add tests.

Comment on lines 51 to 52
System.err.println("Invalid format for system property " + key);
throw e;
Copy link
Owner

Choose a reason for hiding this comment

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

No console logging allowed. Just re-throw with more context information.

@@ -27,4 +34,24 @@ public final class Limits {
private Limits() {
}

/**
* Retrieves the system property value as an integer, with a fallback to a default value.
* If the property is not set or cannot be parsed, the default value is returned.
Copy link
Owner

Choose a reason for hiding this comment

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

The implementation does not use the default value if it cannot be parsed (which is good IMO). The same applies to the documentation of the defaultValue and return value.

*/
private static int getIntProperty(String key, int defaultValue) {
String value = System.getProperty(key);
if (value != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please invert the logic to have shorter branch.

@@ -2,6 +2,13 @@

/**
* The {@code Limits} class defines the maximum limits for various fields and records in a CSV file.
* <p>
* Properties can be overridden by using
Copy link
Owner

Choose a reason for hiding this comment

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

by using ... ?

return Integer.parseInt(value);
} catch (NumberFormatException e) {
System.err.println("Invalid format for system property " + key);
throw e;
Copy link
Owner

Choose a reason for hiding this comment

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

@throws is missing in javadoc

Copy link

codecov bot commented Apr 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.34%. Comparing base (b648663) to head (7f0b9db).

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #112      +/-   ##
============================================
+ Coverage     98.32%   98.34%   +0.01%     
- Complexity      390      393       +3     
============================================
  Files            31       32       +1     
  Lines          1136     1145       +9     
  Branches        160      161       +1     
============================================
+ Hits           1117     1126       +9     
  Misses            9        9              
  Partials         10       10              

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

Comment on lines 3 to 4
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
Copy link
Owner

Choose a reason for hiding this comment

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

FastCSV uses AssertJ-Assertions exclusively.

Comment on lines 12 to 16
@BeforeEach
void setup() {
System.clearProperty("fastcsv.max.field.size");
System.clearProperty("fastcsv.max.field.count");
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand why this is required. Isn't AfterEach sufficient?

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class LimitsTest {
Copy link
Owner

Choose a reason for hiding this comment

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

The two properties (fastcsv.max.field.size and fastcsv.max.field.count) should be declared as constants in order to not repeat them over and over again...

@Obolrom Obolrom requested a review from osiegmar April 27, 2024 18:47
@osiegmar osiegmar merged commit 8419a80 into osiegmar:main Apr 28, 2024
5 checks passed
@osiegmar
Copy link
Owner

Thank you!

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