GabrielBrascher opened a new pull request #4268:
URL: https://github.com/apache/cloudstack/pull/4268
## Description
<!--- Describe your changes in detail -->
Recently I had a few DB connection/transaction issues on a test environment
and one of the log messages was the following `NullPointerException`:
```
2020-08-12 22:48:33,250 WARN [c.c.a.m.AgentManagerImpl]
(AgentManager-Handler-1:null) (logid:) Caught:
java.lang.NullPointerException
at com.cloud.utils.db.GenericDaoBase.update(GenericDaoBase.java:853)
at com.cloud.utils.db.GenericDaoBase.update(GenericDaoBase.java:809)
at com.cloud.utils.db.GenericDaoBase.update(GenericDaoBase.java:1365)
```
Looking further we can see that the null pointer was caused due to a null
Object calling _equals_ method. A simple fix would be to use the static final
not-null Object calling the `Object.equals` method.
This PR also extracted the duplicated code that could cause
`NullPointerException` and added unit tests to ensure that no
`NullPointerException` will be thrown.
## Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]