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

SLING-8116 implement OSGI Converter for default methods #8

Merged
merged 4 commits into from
Dec 17, 2018

Conversation

JEBailey
Copy link
Contributor

@JEBailey JEBailey commented Nov 26, 2018

Implements default methods in the ValueMap interface for the get(key,class) and get(key, default) methods that will rely on the Converter class from the OSGi standard.

This will result in the following
ValueMapDecorator will now return null when converting an existing array to an unsupported Type as other ValueMap implementations do.
ValueMapDecorator will return a null when converting a missing property to an array, as other ValueMap implementations do.
ValueMaps relying on the default methods will now support the autoboxing to primitive arrays during conversion
ValueMaps relying on the default methods will return true for a conversion of a char or number that is not '0' to a Boolean
ValueMaps relying on the default methods will return false for any value that can not be converted to Boolean.TRUE
Will return false for a null property

package has been updated to jre8 to support default methods

@JEBailey
Copy link
Contributor Author

@rombert , @cziegeler any feedback is appreciated.

@rombert
Copy link
Contributor

rombert commented Nov 30, 2018

Did not get much time to review it fully but I think that we should preserve backwards compatibility with the previous implementation. So changes in tests are a sign we should override the default converters behaviour and supply our own.

@JEBailey
Copy link
Contributor Author

The question then becomes, should we maintain backward compatibility with how the ValueMap works or the ValueMapDecorator?

@JEBailey
Copy link
Contributor Author

JEBailey commented Dec 2, 2018

I'll review the changes to the test cases. My focus will be to confirm that the behaviour I'm testing will match the expectations of what is defined in the ValueMap and update the converter accordingly

rombert
rombert previously requested changes Dec 3, 2018
@@ -52,7 +52,7 @@

<properties>
<site.jira.version.id>12314252</site.jira.version.id>
<sling.java.version>7</sling.java.version>
<sling.java.version>8</sling.java.version>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is OK but I think should be called out in the commit message, to make it clear it was intentional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree


private static Converter converter;

private static synchronized Converter getConverter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be careful when adding syncrhonized static blocks in this class - it's bound to create contention under heavy load. Perhaps using another singleton pattern such as the enum-based one will get us lazy initialisation and also remove any contention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not familiar with that pattern, I'll see what I can implement

return Date.from(Instant.parse(date));
}

public static Date toDate(Calendar cal) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this method need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I'll change that.

@rombert
Copy link
Contributor

rombert commented Dec 3, 2018

should we maintain backward compatibility with how the ValueMap works or the ValueMapDecorator?

@JEBailey - by that do you mean the variation you spotted on the mailing list?

the ValueMapDecorator will return different results depending on whether you've wrapped a ValueMap or a non-ValueMap. Because the ObjectConverter class that we created internally will return an empty array if a conversion fails versus the ValueMap which will return null.

I would slightly lean towards not returning null values but TBH I don't have that much knowledge in ValueMap-land

@JEBailey
Copy link
Contributor Author

JEBailey commented Dec 4, 2018

@rombert Yes, it appears that the ValueMap decorator was returning something different. I need to go through and double check all the changes. FWIW I'm a big fan of returning empty collections over a null value myself, but that doesn't appear to be the way that Sling has done things in the past. Although I couldn't predict the outcome of making that change to returning empty sets

@JEBailey
Copy link
Contributor Author

JEBailey commented Dec 6, 2018

@rombert The only thing I changed in the tests were the results of the ValueMapDecorator. Which has logic that is inconsistent with every other ValueMap implementation. All other ValueMap implementations I've found assume that failure to convert one type to another returns a null.

removed unused import from ValueMap, removed NotNull annotation from
CompositeValueMap to match prior implementation. And verified that jre
was set to version 8. Which was done to support default methods.
@JEBailey
Copy link
Contributor Author

@rombert did I address your concerns? Or did I miss something?

@JEBailey JEBailey dismissed rombert’s stale review December 13, 2018 17:53

changes were made based on feedback

@JEBailey JEBailey merged commit 32a51c0 into master Dec 17, 2018
@raducotescu raducotescu deleted the SLING-8116 branch November 14, 2019 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants