Resolve remaining nullability warnings
Issue: SPR-15869
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.apache.commons.pool2.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.aop.TargetSource} implementation that holds
|
||||
@@ -230,6 +231,7 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem
|
||||
*/
|
||||
@Override
|
||||
public Object getTarget() throws Exception {
|
||||
Assert.state(this.pool != null, "No Commons ObjectPool available");
|
||||
return this.pool.borrowObject();
|
||||
}
|
||||
|
||||
@@ -238,17 +240,19 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem
|
||||
*/
|
||||
@Override
|
||||
public void releaseTarget(Object target) throws Exception {
|
||||
this.pool.returnObject(target);
|
||||
if (this.pool != null) {
|
||||
this.pool.returnObject(target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveCount() throws UnsupportedOperationException {
|
||||
return this.pool.getNumActive();
|
||||
return (this.pool != null ? this.pool.getNumActive() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIdleCount() throws UnsupportedOperationException {
|
||||
return this.pool.getNumIdle();
|
||||
return (this.pool != null ? this.pool.getNumIdle() : 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -257,8 +261,10 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem
|
||||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
logger.debug("Closing Commons ObjectPool");
|
||||
this.pool.close();
|
||||
if (this.pool != null) {
|
||||
logger.debug("Closing Commons ObjectPool");
|
||||
this.pool.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user