Skip to content

Refactor WrapperProperties template to remove caching and simplify implementation #2436

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

Merged
merged 2 commits into from
Jun 12, 2025

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented Jun 5, 2025

This commit refactors the WrapperProperties template used for Maven model properties:

TEMPLATE CHANGES (src/mdo/java/WrapperProperties.java):

  • Removed caching mechanism (orderedProps field and ensureInitialized() method)
  • Simplified read operations to directly delegate to getter.get()
  • Introduced writeOperation() pattern for all write operations that:
    • Creates a fresh OrderedProperties from current state
    • Performs the operation on the copy
    • Only calls setter if changes were made
  • All write operations now use synchronized writeOperation() wrapper
  • Maintains insertion order through OrderedProperties inner class
  • Supports multiple wrapper instances sharing the same backend storage

The new approach eliminates cache invalidation complexity while ensuring:

  • Thread safety through synchronized write operations
  • Insertion order preservation
  • Immediate visibility of changes across wrapper instances
  • Proper delegation to underlying storage

SIDE EFFECTS:

  • Consolidated redundant test classes into single PropertiesTest
  • Removed PropertiesOrderTest and WrapperPropertiesOrderTest (functionality covered by PropertiesTest)
  • Cleaned up duplicate test methods in PropertiesTest

This refactoring simplifies the WrapperProperties implementation while maintaining
all required functionality for Maven model property management.

…plementation

This commit refactors the WrapperProperties template used for Maven model properties:

TEMPLATE CHANGES (src/mdo/java/WrapperProperties.java):
- Removed caching mechanism (orderedProps field and ensureInitialized() method)
- Simplified read operations to directly delegate to getter.get()
- Introduced writeOperation() pattern for all write operations that:
  * Creates a fresh OrderedProperties from current state
  * Performs the operation on the copy
  * Only calls setter if changes were made
- All write operations now use synchronized writeOperation() wrapper
- Maintains insertion order through OrderedProperties inner class
- Supports multiple wrapper instances sharing the same backend storage

The new approach eliminates cache invalidation complexity while ensuring:
- Thread safety through synchronized write operations
- Insertion order preservation
- Immediate visibility of changes across wrapper instances
- Proper delegation to underlying storage

SIDE EFFECTS:
- Consolidated redundant test classes into single PropertiesTest
- Removed PropertiesOrderTest and WrapperPropertiesOrderTest (functionality covered by PropertiesTest)
- Cleaned up duplicate test methods in PropertiesTest

This refactoring simplifies the WrapperProperties implementation while maintaining
all required functionality for Maven model property management.
@gnodet gnodet force-pushed the cleanup-redundant-properties-tests branch from a345aea to 81bc67c Compare June 5, 2025 11:54
Pankraz76

This comment was marked as off-topic.

props.storeToXML(os, comment, encoding);
}


private Object writeReplace() throws java.io.ObjectStreamException {
Properties props = new Properties();
props.putAll(getter.get());
OrderedProperties props = new OrderedProperties(getter.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

yes it is, its declared L:340 and used L:341 in return props;.

lets just ask judge PMD, im sure it will point out the same.

image

@gnodet gnodet requested a review from cstamas June 7, 2025 07:01
@gnodet gnodet added this to the 4.0.0-rc-4 milestone Jun 7, 2025
setter.accept(orderedProps);
writeOperation(properties -> {
runner.perform(properties);
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return null;
return null;

format seems broken as offset.

Comment on lines +195 to +196
runner.perform(properties);
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
runner.perform(properties);
return null;
runner.perform(properties);
return null;

format seems broken as offset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use auto formatting, so either it fails or we need to accept the output. If the CI test pass, we cannot change the formatting.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, thanks.

Comment on lines +39 to +40
@Nested
class OrderPreservationTests {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Nested
class OrderPreservationTests {

why nested if no rivals?

i like this, but only if its really in use. ATM it seems not.

FYI: see the nested feature again. @elharo

Copy link
Contributor

@Pankraz76 Pankraz76 Jun 12, 2025

Choose a reason for hiding this comment

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

overhead for no obvious reason, seems to be the thing here all around.

assertEquals("putall.value1", wrapper.getProperty("putall.key1"));
assertEquals("putall.value2", wrapper.getProperty("putall.key2"));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
}

@gnodet gnodet merged commit 276f9e7 into apache:master Jun 12, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants