Repository: alibaba/fescar
Pull request #551 (2019-03-07 12:36:47)

Try to fix ConfigType NPE
<!-- Please make sure you have read and understood the contributing guidelines -->

### Ⅰ. Try to fix ConfigType NPE

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/alibaba/fescar?pullRequest=551) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/alibaba/fescar?pullRequest=551) before we can accept your contribution.<br/><hr/>**Fay** seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/alibaba/fescar?pullRequest=551) it.</sub>
slievrly: UT build failed
codecov-io: # [Codecov](https://codecov.io/gh/alibaba/fescar/pull/551?src=pr&el=h1) Report
> Merging [#551](https://codecov.io/gh/alibaba/fescar/pull/551?src=pr&el=desc) into [develop](https://codecov.io/gh/alibaba/fescar/commit/389ff7c994782921b84ddf2c1edcb4a4d41da5c5?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `44.44%`.

[![Impacted file tree graph](https://codecov.io/gh/alibaba/fescar/pull/551/graphs/tree.svg?width=650&token=Hy9a6MCc4p&height=150&src=pr)](https://codecov.io/gh/alibaba/fescar/pull/551?src=pr&el=tree)

```diff
@@              Coverage Diff              @@
##             develop     #551      +/-   ##
=============================================
- Coverage      31.95%   31.91%   -0.04%     
+ Complexity       755      754       -1     
=============================================
  Files            198      198              
  Lines           7751     7751              
  Branches         924      924              
=============================================
- Hits            2477     2474       -3     
- Misses          5020     5023       +3     
  Partials         254      254
```


| [Impacted Files](https://codecov.io/gh/alibaba/fescar/pull/551?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [...om/alibaba/fescar/config/ConfigurationFactory.java](https://codecov.io/gh/alibaba/fescar/pull/551/diff?src=pr&el=tree#diff-Y29uZmlnL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL2NvbmZpZy9Db25maWd1cmF0aW9uRmFjdG9yeS5qYXZh) | `0% <0%> (ø)` | `0 <0> (ø)` | :arrow_down: |
| [...ain/java/com/alibaba/fescar/config/ConfigType.java](https://codecov.io/gh/alibaba/fescar/pull/551/diff?src=pr&el=tree#diff-Y29uZmlnL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL2NvbmZpZy9Db25maWdUeXBlLmphdmE=) | `100% <100%> (ø)` | `4 <3> (-1)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/alibaba/fescar/pull/551?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/alibaba/fescar/pull/551?src=pr&el=footer). Last update [389ff7c...47ce65b](https://codecov.io/gh/alibaba/fescar/pull/551?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/config/src/main/java/com/alibaba/fescar/config/ConfigType.java b/config/src/main/java/com/alibaba/fescar/config/ConfigType.java
index 1afb4ec95..02c5d5516 100644
--- a/config/src/main/java/com/alibaba/fescar/config/ConfigType.java
+++ b/config/src/main/java/com/alibaba/fescar/config/ConfigType.java
@@ -16,6 +16,7 @@
 
 package com.alibaba.fescar.config;
 
+
 import com.alibaba.fescar.common.exception.NotSupportYetException;
 
 /**
@@ -45,14 +46,11 @@ public enum ConfigType {
      * @return the type
      */
     public static ConfigType getType(String name) {
-        if (File.name().equalsIgnoreCase(name)) {
-            return File;
-        } else if (Nacos.name().equalsIgnoreCase(name)) {
-            return Nacos;
-        } else if (Apollo.name().equalsIgnoreCase(name)) {
-            return Apollo;
-        } else {
-            throw new NotSupportYetException("unsupport type:" + name);
+        for (ConfigType configType : values()) {
+            if (configType.name().equalsIgnoreCase(name)) {
+                return configType;
+            }
         }
+        throw new IllegalArgumentException("illegal type:" + name);
     }
 }
diff --git a/config/src/main/java/com/alibaba/fescar/config/ConfigurationFactory.java b/config/src/main/java/com/alibaba/fescar/config/ConfigurationFactory.java
index 7e28e8e65..9c151bbff 100644
--- a/config/src/main/java/com/alibaba/fescar/config/ConfigurationFactory.java
+++ b/config/src/main/java/com/alibaba/fescar/config/ConfigurationFactory.java
@@ -46,12 +46,13 @@ public final class ConfigurationFactory {
      */
     public static Configuration getInstance() {
         ConfigType configType = null;
+        String configTypeName = null;
         try {
-            configType = ConfigType.getType(
-                FILE_INSTANCE.getConfig(ConfigurationKeys.FILE_ROOT_CONFIG + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR
-                    + ConfigurationKeys.FILE_ROOT_TYPE));
+            configTypeName = FILE_INSTANCE.getConfig(ConfigurationKeys.FILE_ROOT_CONFIG + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR
+                    + ConfigurationKeys.FILE_ROOT_TYPE);
+            configType = ConfigType.getType(configTypeName);
         } catch (Exception exx) {
-            LOGGER.error(exx.getMessage());
+            throw new NotSupportYetException("not support register type: " + configTypeName);
         }
         Configuration configuration;
         switch (configType) {


Test patch:
diff --git a/config/src/test/java/com/alibaba/fescar/config/ConfigTypeTest.java b/config/src/test/java/com/alibaba/fescar/config/ConfigTypeTest.java
index 57d428475..24e9c76b0 100644
--- a/config/src/test/java/com/alibaba/fescar/config/ConfigTypeTest.java
+++ b/config/src/test/java/com/alibaba/fescar/config/ConfigTypeTest.java
@@ -58,7 +58,7 @@ public class ConfigTypeTest {
     /**
      * Test get type with not support.
      */
-    @Test(expected = NotSupportYetException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testGetTypeWithNotSupport() {
         ConfigType.getType("none");
     }