Skip to content

Commit

Permalink
Use #ruby_first to solve Java21's List#first incompatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Jan 18, 2025
1 parent 356963b commit a1b392d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/openhab/core/items/semantics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ def lookup(id, locale = java.util.Locale.default)

# @deprecated OH3.4 missing registry
if Provider.registry
tag = service.get_by_label_or_synonym(id, locale)
tag = nil if tag&.empty?
tag_class = tag&.first ||
# Java21 added #first method, which overrides Ruby's #first.
# It throws an error if the list is Empty instead of returning nil.
# So we use #ruby_first to ensure we get Ruby's behaviour
tag_class = service.get_by_label_or_synonym(id, locale).ruby_first ||
Provider.registry.get_tag_class_by_id(id)
return unless tag_class

Expand Down

0 comments on commit a1b392d

Please sign in to comment.