MISC: Improved code quality 79/13079/1
authordonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 28 Nov 2013 00:06:43 +0000 (09:06 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 28 Nov 2013 00:06:43 +0000 (09:06 +0900)
Improved code quality and avoid NPE

Change-Id: I750a050dc8ea807cddfd8ac6d214a624af5259d4
Signed-off-by: donghyuk.yang <donghyuk.yang@samsung.com>
org.tizen.nativeplatform/src/org/tizen/nativeplatform/indexer/IndexerPreferenceProcessor.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformLaunchDelegateForCoredump.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/wizard/pages/PlatformLaunchSettingRootstrapPage.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderCommon.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncherUtil.java

index 226a581..d5a494d 100644 (file)
@@ -27,6 +27,10 @@ public class IndexerPreferenceProcessor {
     }
 
     public boolean process() {
+        if (project != null) {
+            logger.warn("Failed to set default indexer: Project is null");
+            return false;
+        }
         IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
         IConfiguration config = info.getDefaultConfiguration();
         IManagedProject managedProject = config.getManagedProject();
@@ -40,9 +44,7 @@ public class IndexerPreferenceProcessor {
         }
 
         int scope = IndexerPreferences.SCOPE_PROJECT_PRIVATE;
-        if (project != null) {
-            IndexerPreferences.setScope(project, scope);
-        }
+        IndexerPreferences.setScope(project, scope);
         boolean useActive = true;
         ICProjectDescriptionManager prjDescMgr = CCorePlugin.getDefault()
                 .getProjectDescriptionManager();
index 24ca9a5..b2fbc8d 100644 (file)
@@ -150,9 +150,15 @@ public class PlatformLaunchDelegateForCoredump extends PlatformLaunchDelegate {
                     dlg.create();
                     if (Window.OK == dlg.open()) {
                         String programPath = dlg.getProgramPath();
-                        String coredumpPath = dlg.getCoredumpModel().getPath();
-                        String originCoredumpPath = dlg.getCoredumpModel().getOriginPath();
-                        String coredumpLocation = dlg.getCoredumpModel().getLocation().toString();
+                        String coredumpPath = "";
+                        String originCoredumpPath = "";
+                        String coredumpLocation = "";
+                        CoredumpModel cmodel = dlg.getCoredumpModel();
+                        if (cmodel != null) {
+                            coredumpPath = dlg.getCoredumpModel().getPath();
+                            originCoredumpPath = dlg.getCoredumpModel().getOriginPath();
+                            coredumpLocation = dlg.getCoredumpModel().getLocation().toString();
+                        }
                         rootstrap = dlg.getSelectedRootstrap();
                         target.setRootstrap(rootstrap);
                         String rootstrapName = rootstrap.getName();
@@ -341,7 +347,7 @@ public class PlatformLaunchDelegateForCoredump extends PlatformLaunchDelegate {
         }
         IPkgCommander commander = target.getCommander(CmdTargetTypes.ROOTSTRAP);
         ICommandStatus status = commander.copyFile(path, dstPath);
-        if (!status.isOk()) {
+        if (status == null || !status.isOk()) {
             logger.error(String.format("Faile to copy coredump file: %s -> %s", path, dstPath));
             return null;
         }
index 4b930eb..8c04a8d 100644 (file)
@@ -415,8 +415,10 @@ public class PlatformLaunchSettingRootstrapPage extends PlatformLaunchCommonPage
             data = new ArrayList<String>();
             if (selectIdx >= 0) {
                 List<ICheckTreeItem> children = snapshotInfos.get(selectIdx).getChildren();
-                for (int idx = 0; idx < children.size(); idx++) {
-                    data.add(children.get(idx).getText());
+                if (children != null) {
+                    for (int idx = 0; idx < children.size(); idx++) {
+                        data.add(children.get(idx).getText());
+                    }
                 }
             }
         }
index d25d345..df07aed 100644 (file)
@@ -136,7 +136,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
     }
 
     public String getLogs() {
-        if (rec == null) {
+        if (rec == null || rec.getLog() == null) {
             return null;
         }
         StringBuffer sb = new StringBuffer();
@@ -767,7 +767,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
                 ZypperTool.refreshRepoCommandXmlOut());
         PackageManagerOuputReceiver hrec = getNewOuputReceiver();
         ICommandStatus status = execute(command, hrec, 10000, null);
-        if (!status.isOk()) {
+        if (status == null || !status.isOk()) {
             printResultLog("Failed to refresh repository");
         } else {
             List<String> value = status.getValues();
@@ -787,10 +787,9 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
         String command = makeCommand(getProxyCommand(), getResetRpmDb(),
                 ZypperTool.refreshRepoCommand());
         ICommandStatus status = execute(command, 10000, null);
-        if (!status.isOk()) {
+        if (status == null || !status.isOk()) {
             printResultLog("Failed to refresh repository");
         }
-
         return status;
     }
 
@@ -982,11 +981,11 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
                 ZypperTool.searchPkgCommandWithXmlOut(pkg));
         PackageManagerOuputReceiver hrec = getNewOuputReceiver();
         ICommandStatus status = execute(command, hrec, null);
+        PkgInstallTypes result = PkgInstallTypes.NOT_EXISTS;
         if (!status.isOk()) {
             printResultLog("Failed to get remote package list");
-            return PkgInstallTypes.NOT_EXISTS;
+            return result;
         }
-        PkgInstallTypes result = null;
         List<String> value = status.getValues();
         if (value != null && value.size() > 0) {
             String xml = makeNewlineString(value);
@@ -997,8 +996,6 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
                 result = PkgInstallTypes.INSTALLED;
             } else if (log.equals("not-installed")) {
                 result = PkgInstallTypes.NOT_INSTALLED;
-            } else {
-                result = PkgInstallTypes.NOT_EXISTS;
             }
         }
         return result;
index 3f91d41..d9ac6ca 100644 (file)
@@ -344,6 +344,7 @@ public class CommandLauncherUtil {
                         expectScript.getAbsoluteFile()), e);
                 cleanUpScript(expectScript.getPath());
             }
+            return null;
         } finally {
             tryClose(bw);
         }
@@ -416,6 +417,7 @@ public class CommandLauncherUtil {
             tryClose(bw);
         }
 
+        // execute script
         return shellScript.getPath();
     }