From 33720e8d97d0503039728b56d2c5a434dc24d366 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 21 May 2020 12:47:55 +0200 Subject: [PATCH] [core] Fix potential NPE in Java7ZlibInputOutputStream The field XMPPInputOutputStream.flushMethod was not initialized, which could cause an NPE in the "switch (flushMethod)" found in Java7ZlibInputOutputStream.getOutputStream(). --- .../smack/compression/XMPPInputOutputStream.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/compression/XMPPInputOutputStream.java b/smack-core/src/main/java/org/jivesoftware/smack/compression/XMPPInputOutputStream.java index 837028c64..5f133a640 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/compression/XMPPInputOutputStream.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/compression/XMPPInputOutputStream.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013-2018 Florian Schmaus + * Copyright 2013-2020 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.jivesoftware.smack.util.Objects; + public abstract class XMPPInputOutputStream { - protected static FlushMethod flushMethod; + protected static FlushMethod flushMethod = FlushMethod.SYNC_FLUSH; /** * Set the used flushed method when compressing data. The default is full flush which may not @@ -33,7 +35,7 @@ public abstract class XMPPInputOutputStream { * @param flushMethod TODO javadoc me please */ public static void setFlushMethod(FlushMethod flushMethod) { - XMPPInputOutputStream.flushMethod = flushMethod; + XMPPInputOutputStream.flushMethod = Objects.requireNonNull(flushMethod); } public static FlushMethod getFlushMethod() {