This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git
The following commit(s) were added to refs/heads/trunk by this push:
new 921fee3 Improved: Fix some bugs Spotbugs reports (OFBIZ-12386)
921fee3 is described below
commit 921fee3c0c45bba25c4aa69f50621b7e3050d8d7
Author: Jacques Le Roux <[email protected]>
AuthorDate: Tue Dec 21 14:19:40 2021 +0100
Improved: Fix some bugs Spotbugs reports (OFBIZ-12386)
In OFBizActiveDirectoryAuthenticationHandler class, fixes a possible NPE:
Immediate dereferencement of the result of readLine()
(NP_IMMEDIATE_DEREFERENCE_OF_READLINE)
The result of invoking readLine() is immediately dereferenced. If there are
no
more lines of text to read, readLine() will return null and dereferencing
that
will generate a null pointer exception.
---
.../ldap/cas/OFBizCasAuthenticationHandler.java | 25 ++++++----------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git
a/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java
b/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java
index b5083ae..56b420e 100644
---
a/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java
+++
b/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java
@@ -80,33 +80,20 @@ public final class OFBizCasAuthenticationHandler extends
AbstractOFBizAuthentica
// there's a ticket, we should validate the ticket
URL validateURL = new URL(casUrl + validateUri + "?" +
PARAM_TICKET + "=" + ticket + "&" + PARAM_SERVICE + "=" + url);
URLConnection conn = validateURL.openConnection();
- InputStreamReader result = null;
- BufferedReader reader = null;
- try {
- result = new InputStreamReader(conn.getInputStream(), "UTF-8");
- reader = new BufferedReader(result);
+ try (InputStreamReader result = new
InputStreamReader(conn.getInputStream(), "UTF-8");
+ BufferedReader reader = new BufferedReader(result)) {
String oneline = reader.readLine();
if (oneline != null && "yes".equals(oneline)) {
// the ticket is true
- username = reader.readLine().trim();
+ username = reader.readLine();
+ if (username != null) {
+ username = username.trim();
+ }
casLoggedIn = true;
} else {
// the ticket is false, forward the request to cas login
page
response.sendRedirect(casUrl + loginUri + "?service=" +
url);
}
- } catch (Exception e) {
- if (reader != null) {
- try {
- reader.close();
- } catch (Exception e1) {
- }
- }
- if (result != null) {
- try {
- result.close();
- } catch (Exception e1) {
- }
- }
}
}