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

Persistence extensions: allow null serviceId #4213

Merged
merged 2 commits into from May 6, 2024

Conversation

mherwege
Copy link
Contributor

@mherwege mherwege commented May 3, 2024

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
@mherwege mherwege requested a review from a team as a code owner May 3, 2024 17:13
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

Otherwise a nice addition.

@@ -80,7 +80,7 @@ public PersistenceExtensions(@Reference PersistenceServiceRegistry registry,
* @param item the item to store
*/
public static void persist(Item item) {
internalPersist(item);
internalPersist(item, (String) null);
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need a cast to String here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was needed when I only half changed the file (version with signature internalPersist(Item, TimeSeries)), but no longer needed, so removed.

String serviceId = getDefaultServiceId();
if (serviceId == null) {
private static void internalPersist(Item item, @Nullable String serviceId) {
String sId = serviceId == null ? getDefaultServiceId() : serviceId;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
String sId = serviceId == null ? getDefaultServiceId() : serviceId;
String effectiveServiceId = Objects.requireNonNullElse(serviceId, getDefaultServiceId());

Also below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@J-N-K J-N-K added the enhancement An enhancement or new feature of the Core label May 4, 2024
@jimtng
Copy link
Contributor

jimtng commented May 4, 2024

Perhaps label this as regression?

@jimtng
Copy link
Contributor

jimtng commented May 4, 2024

Also to ensure that this is honored in the future, could we please add some tests to check?

@J-N-K
Copy link
Member

J-N-K commented May 4, 2024

I don't think it's a regression. It didn't work before, right?

@jimtng
Copy link
Contributor

jimtng commented May 4, 2024

I don't think it's a regression. It didn't work before, right?

It worked like this before #3736:
When given null as the serviceId, it would use the default serviceId, the same as when the serviceId is omitted completely.

#3736 removed this and instead, it actually looks up null in the PersistenceServiceRegistry and naturally not find it, and as a result, fails the call by returning null. So yes this is very much a regression, although as noted, this behaviour wasn't documented in the javadoc.

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
@mherwege
Copy link
Contributor Author

mherwege commented May 6, 2024

When given null as the serviceId, it would use the default serviceId, the same as when the serviceId is omitted completely.

True, it would, but relying on it was dangerous. For some actions it did not work, and for others it gave wrong result as it was never meant to be used like that. For some, you got lucky and it actually did end up giving the right result.

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

Thanks!

@J-N-K J-N-K merged commit 03a9708 into openhab:main May 6, 2024
5 checks passed
@J-N-K J-N-K added this to the 4.2 milestone May 6, 2024
@mherwege mherwege deleted the persistence_extension branch May 6, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants