You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2025/06/16 19:48:00 UTC

[jira] [Commented] (ARTEMIS-5534) Use Objects.requireNonNullElse() where sensible

    [ https://issues.apache.org/jira/browse/ARTEMIS-5534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17979311#comment-17979311 ] 

ASF subversion and git services commented on ARTEMIS-5534:
----------------------------------------------------------

Commit a2009d15402e1f595cf9c4b2ad01c2209ca87d11 in activemq-artemis's branch refs/heads/main from Justin Bertram
[ https://gitbox.apache.org/repos/asf?p=activemq-artemis.git;h=a2009d1540 ]

ARTEMIS-5534 use Objects.requireNonNullElse... where sensible

The code-base is littered with uses of Java's ternary operator to check
for null and fallback to a default value. Many of these can be replaced
with either `Objects.requireNonNullElse` or
`Objects.requireNonNullElseGet`. The latter is used where appropriate
to essentially match the short-circuit semantics provided by the
ternary operator.


> Use Objects.requireNonNullElse() where sensible
> -----------------------------------------------
>
>                 Key: ARTEMIS-5534
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-5534
>             Project: ActiveMQ Artemis
>          Issue Type: Task
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> There are lots of places across the code-base which do a check like this:
> {code:java}
> foo != null ? foo : bar{code}
> or
> {code:java}
> foo == null ? bar : foo{code}
> Many of these can be replaced, e.g.:
> {code:java}
> Objects.requireNonNullElse(foo, bar){code}
> Also, code like:
> {code:java}
> foo != null ? foo : calculateBar(){code}
> Can be replaced with something like:
> {code:java}
> Objects.requireNonNullElseGet(foo, () -> calculateBar()){code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@activemq.apache.org
For additional commands, e-mail: issues-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact