You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/04/24 02:59:38 UTC
[james-project] 03/17: [Refactoring] use requireNonNullElseGet and
requireNonNullElse when handling null
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit fcc0b3ef81814c28bd13857bf74e51fe9a76cede
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 21 15:36:03 2020 +0200
[Refactoring] use requireNonNullElseGet and requireNonNullElse when handling null
---
.../org/apache/james/mailbox/store/LazyMimeDescriptor.java | 8 ++------
.../org/apache/james/imap/decode/DecodingException.java | 11 +++--------
.../james/imap/processor/fetch/FetchResponseBuilder.java | 8 ++------
.../context/web/JamesServerWebApplicationContext.java | 14 ++++----------
4 files changed, 11 insertions(+), 30 deletions(-)
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java
index f4fc8c4..e1d4ae2 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java
@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Header;
@@ -121,12 +122,7 @@ public class LazyMimeDescriptor implements MimeDescriptor {
@Override
public long getLines() {
- Long count = message.getTextualLineCount();
- if (count == null) {
- return -1;
- } else {
- return count;
- }
+ return Objects.requireNonNullElse(message.getTextualLineCount(), -1L);
}
@Override
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/DecodingException.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/DecodingException.java
index db323ff..678c58b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/DecodingException.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/DecodingException.java
@@ -20,6 +20,7 @@
package org.apache.james.imap.decode;
import java.io.IOException;
+import java.util.Objects;
import org.apache.james.imap.api.display.HumanReadableText;
@@ -85,14 +86,8 @@ public class DecodingException extends IOException {
* @return the key, not null
*/
public final HumanReadableText getKey() {
- final HumanReadableText key;
- if (this.key == null) {
- // API specifies not null but best to default to generic message
- key = HumanReadableText.ILLEGAL_ARGUMENTS;
- } else {
- key = this.key;
- }
- return key;
+ // API specifies not null but best to default to generic message
+ return Objects.requireNonNullElse(this.key, HumanReadableText.ILLEGAL_ARGUMENTS);
}
@Override
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
index 8484b39..40cd7f6 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
@@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import javax.mail.Flags;
@@ -252,12 +253,7 @@ public final class FetchResponseBuilder {
if (firstOctet == null) {
result = fullResult;
} else {
- final long numberOfOctetsAsLong;
- if (numberOfOctets == null) {
- numberOfOctetsAsLong = Long.MAX_VALUE;
- } else {
- numberOfOctetsAsLong = numberOfOctets;
- }
+ final long numberOfOctetsAsLong = Objects.requireNonNullElse(numberOfOctets, Long.MAX_VALUE);
final long firstOctetAsLong = firstOctet;
result = new PartialFetchBodyElement(fullResult, firstOctetAsLong, numberOfOctetsAsLong);
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java b/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java
index b073a39..4a6f22c 100644
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java
+++ b/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java
@@ -18,6 +18,8 @@
****************************************************************/
package org.apache.james.container.spring.context.web;
+import java.util.Objects;
+
import org.apache.james.container.spring.resource.DefaultJamesResourceLoader;
import org.apache.james.container.spring.resource.JamesResourceLoader;
import org.apache.james.filesystem.api.JamesDirectoriesProvider;
@@ -48,11 +50,7 @@ public class JamesServerWebApplicationContext extends XmlWebApplicationContext i
*/
@Override
public String getConfDirectory() {
- if (confDirectory == null) {
- return getRootDirectory() + "/WEB-INF/conf/";
- } else {
- return confDirectory;
- }
+ return Objects.requireNonNullElseGet(confDirectory, () -> getRootDirectory() + "/WEB-INF/conf/");
}
/**
@@ -71,11 +69,7 @@ public class JamesServerWebApplicationContext extends XmlWebApplicationContext i
*/
@Override
public String getVarDirectory() {
- if (varDirectory == null) {
- return getRootDirectory() + "/var/";
- } else {
- return varDirectory;
- }
+ return Objects.requireNonNullElseGet(varDirectory, () -> getRootDirectory() + "/var/");
}
});
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org