ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject ignite git commit: IGNITE-3713 .NET: Fix possible NPE in PlatformConfigurationUtils due to null Enum values
Date Mon, 22 Aug 2016 09:23:30 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 05c5939ae -> 354318ad9


IGNITE-3713 .NET:  Fix possible NPE in PlatformConfigurationUtils due to null Enum values


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/354318ad
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/354318ad
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/354318ad

Branch: refs/heads/master
Commit: 354318ad9fca00c0cb5d9f58db73ca81366f3ee4
Parents: 05c5939
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Mon Aug 22 12:23:22 2016 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Mon Aug 22 12:23:22 2016 +0300

----------------------------------------------------------------------
 .../utils/PlatformConfigurationUtils.java       | 57 +++++++++++++++-----
 1 file changed, 43 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/354318ad/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 1d2baf2..010c2ae 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -343,6 +343,7 @@ public class PlatformConfigurationUtils {
      * @param out Stream.
      * @param p Policy.
      */
+    @SuppressWarnings("TypeMayBeWeakened")
     private static void writeEvictionPolicy(BinaryRawWriter out, EvictionPolicy p) {
         if (p instanceof FifoEvictionPolicy) {
             out.writeByte((byte)1);
@@ -654,12 +655,10 @@ public class PlatformConfigurationUtils {
         assert writer != null;
         assert ccfg != null;
 
-        writer.writeInt(ccfg.getAtomicityMode() == null ?
-            CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE.ordinal() : ccfg.getAtomicityMode().ordinal());
-        writer.writeInt(ccfg.getAtomicWriteOrderMode() == null ? 0 : ccfg.getAtomicWriteOrderMode().ordinal());
+        writeEnumInt(writer, ccfg.getAtomicityMode(), CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE);
+        writeEnumInt(writer, ccfg.getAtomicWriteOrderMode());
         writer.writeInt(ccfg.getBackups());
-        writer.writeInt(ccfg.getCacheMode() == null ?
-            CacheConfiguration.DFLT_CACHE_MODE.ordinal() : ccfg.getCacheMode().ordinal());
+        writeEnumInt(writer, ccfg.getCacheMode(), CacheConfiguration.DFLT_CACHE_MODE);
         writer.writeBoolean(ccfg.isCopyOnRead());
         writer.writeBoolean(ccfg.isEagerTtl());
         writer.writeBoolean(ccfg.isSwapEnabled());
@@ -674,15 +673,13 @@ public class PlatformConfigurationUtils {
         writer.writeLong(ccfg.getLongQueryWarningTimeout());
         writer.writeInt(ccfg.getMaxConcurrentAsyncOperations());
         writer.writeFloat(ccfg.getEvictMaxOverflowRatio());
-        writer.writeInt(ccfg.getMemoryMode() == null ?
-            CacheConfiguration.DFLT_MEMORY_MODE.ordinal() : ccfg.getMemoryMode().ordinal());
+        writeEnumInt(writer, ccfg.getMemoryMode(), CacheConfiguration.DFLT_MEMORY_MODE);
         writer.writeString(ccfg.getName());
         writer.writeLong(ccfg.getOffHeapMaxMemory());
         writer.writeBoolean(ccfg.isReadFromBackup());
         writer.writeInt(ccfg.getRebalanceBatchSize());
         writer.writeLong(ccfg.getRebalanceDelay());
-        writer.writeInt(ccfg.getRebalanceMode() == null ?
-            CacheConfiguration.DFLT_REBALANCE_MODE.ordinal() : ccfg.getRebalanceMode().ordinal());
+        writeEnumInt(writer, ccfg.getRebalanceMode(), CacheConfiguration.DFLT_REBALANCE_MODE);
         writer.writeLong(ccfg.getRebalanceThrottle());
         writer.writeLong(ccfg.getRebalanceTimeout());
         writer.writeBoolean(ccfg.isSqlEscapeAll());
@@ -693,7 +690,7 @@ public class PlatformConfigurationUtils {
         writer.writeLong(ccfg.getWriteBehindFlushFrequency());
         writer.writeInt(ccfg.getWriteBehindFlushSize());
         writer.writeInt(ccfg.getWriteBehindFlushThreadCount());
-        writer.writeInt(ccfg.getWriteSynchronizationMode() == null ? 0 : ccfg.getWriteSynchronizationMode().ordinal());
+        writeEnumInt(writer, ccfg.getWriteSynchronizationMode());
         writer.writeBoolean(ccfg.isReadThrough());
         writer.writeBoolean(ccfg.isWriteThrough());
 
@@ -790,7 +787,7 @@ public class PlatformConfigurationUtils {
         assert index != null;
 
         writer.writeString(index.getName());
-        writer.writeByte((byte)index.getIndexType().ordinal());
+        writeEnumByte(writer, index.getIndexType());
 
         LinkedHashMap<String, Boolean> fields = index.getFields();
 
@@ -896,7 +893,7 @@ public class PlatformConfigurationUtils {
 
             w.writeInt(atomic.getAtomicSequenceReserveSize());
             w.writeInt(atomic.getBackups());
-            w.writeInt(atomic.getCacheMode().ordinal());
+            writeEnumInt(w, atomic.getCacheMode(), AtomicConfiguration.DFLT_CACHE_MODE);
         }
         else
             w.writeBoolean(false);
@@ -907,8 +904,8 @@ public class PlatformConfigurationUtils {
             w.writeBoolean(true);
 
             w.writeInt(tx.getPessimisticTxLogSize());
-            w.writeInt(tx.getDefaultTxConcurrency().ordinal());
-            w.writeInt(tx.getDefaultTxIsolation().ordinal());
+            writeEnumInt(w, tx.getDefaultTxConcurrency(), TransactionConfiguration.DFLT_TX_CONCURRENCY);
+            writeEnumInt(w, tx.getDefaultTxIsolation(), TransactionConfiguration.DFLT_TX_ISOLATION);
             w.writeLong(tx.getDefaultTxTimeout());
             w.writeInt(tx.getPessimisticTxLogLinger());
         }
@@ -998,6 +995,38 @@ public class PlatformConfigurationUtils {
     }
 
     /**
+     * Writes enum as byte.
+     *
+     * @param w Writer.
+     * @param e Enum.
+     */
+    private static void writeEnumByte(BinaryRawWriter w, Enum e) {
+        w.writeByte(e == null ? 0 : (byte)e.ordinal());
+    }
+
+    /**
+     * Writes enum as int.
+     *
+     * @param w Writer.
+     * @param e Enum.
+     */
+    private static void writeEnumInt(BinaryRawWriter w, Enum e) {
+        w.writeInt(e == null ? 0 : e.ordinal());
+    }
+
+    /**
+     * Writes enum as int.
+     *
+     * @param w Writer.
+     * @param e Enum.
+     */
+    private static void writeEnumInt(BinaryRawWriter w, Enum e, Enum def) {
+        assert def != null;
+
+        w.writeInt(e == null ? def.ordinal() : e.ordinal());
+    }
+
+    /**
      * Private constructor.
      */
     private PlatformConfigurationUtils() {


Mime
View raw message