[ 
https://issues.apache.org/jira/browse/ARTEMIS-4932?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Justin Bertram updated ARTEMIS-4932:
------------------------------------
    Description: 
A problem has been detected in the {{URISchema.java}} file on line 53 and 70.

In a call to the {{getScheme()}} method on a {{defaultFactory}} object, 
{{getScheme()}} may return {{null}} which will throw a {{NullPointerException}} 
when {{equals()}} is called.

To avoid a {{NullPointerException}}, you should check the result of 
{{getScheme()}} for {{null}} before calling {{equals()}}, e.g.:
{code:java}
if (defaultFactory != null && uri.getHost() == null) {
    String defaultScheme = defaultFactory.getScheme();
    if (defaultScheme != null && defaultScheme.equals(uri.getScheme())) {
        uri = defaultFactory;
    }
}{code}

 

  was:
*A problem has been detected in the URISchema file.java on line 53 and 70*

In a call to the getScheme() method on a defaultFactory object, getScheme() may 
return null, which will throw a NullPointerException when equals() is called.

To avoid a NullPointerException, you should check the result of getScheme() for 
null before calling equals().

For example, you could change the code like this:

_if (defaultFactory != null && uri.getHost() == null) {_

_String defaultScheme = defaultFactory.getScheme();_

_if (defaultScheme != null &&_ 
_defaultScheme.equals(uri.getScheme())) {_

    _uri = defaultFactory;_
_}_
_}_

 


> Reference, returned from function 'defaultFactory.getScheme()String' at 
> URISchema.java:53, may be null and is dereferenced at URISchema.java:53.
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: ARTEMIS-4932
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4932
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>    Affects Versions: 2.25.0
>            Reporter: Suhov Roman
>            Priority: Major
>         Attachments: 1.png
>
>
> A problem has been detected in the {{URISchema.java}} file on line 53 and 70.
> In a call to the {{getScheme()}} method on a {{defaultFactory}} object, 
> {{getScheme()}} may return {{null}} which will throw a 
> {{NullPointerException}} when {{equals()}} is called.
> To avoid a {{NullPointerException}}, you should check the result of 
> {{getScheme()}} for {{null}} before calling {{equals()}}, e.g.:
> {code:java}
> if (defaultFactory != null && uri.getHost() == null) {
>     String defaultScheme = defaultFactory.getScheme();
>     if (defaultScheme != null && defaultScheme.equals(uri.getScheme())) {
>         uri = defaultFactory;
>     }
> }{code}
>  



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to