xml: Replace a checkNotNull by a message when state undefined
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Wed, 4 May 2016 19:55:00 +0000 (15:55 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Mon, 30 May 2016 14:09:26 +0000 (10:09 -0400)
An error in the XML where the next state defined by the user was undefined
would throw a NullPointerException and make the analysis fail ungracefully.
This logs a message to the user (we still need a way to have debug data on the
XML)

This is one step in solving bug 493155

Change-Id: I53edc74c6e9abcf531df07d17d7fa488c52e9155
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/72080
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/Messages.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/messages.properties [new file with mode: 0644]

diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/Messages.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/Messages.java
new file mode 100644 (file)
index 0000000..54e55f2
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Externalized messages for this package
+ *
+ * @author Geneviève Bastien
+ */
+public class Messages extends NLS {
+    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.messages"; //$NON-NLS-1$
+
+    /** Message for a state undefined */
+    public static @Nullable String TmfXmlFsm_StateUndefined;
+    static {
+        // initialize resource bundle
+        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+    }
+
+    private Messages() {
+    }
+}
index 00e343d0e48fe7e70a39b1388723c4b07175b163..4d8bd302a27a7ea432078e75392cde615c6e161e 100644 (file)
@@ -17,7 +17,9 @@ import java.util.Map;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder.ScenarioStatusType;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
@@ -204,7 +206,12 @@ public class TmfXmlFsm {
     public @Nullable TmfXmlStateTransition next(ITmfEvent event, Map<String, TmfXmlTransitionValidator> tests, TmfXmlScenarioInfo scenarioInfo) {
         boolean matched = false;
         TmfXmlStateTransition stateTransition = null;
-        TmfXmlState state = NonNullUtils.checkNotNull(fStatesMap.get(scenarioInfo.getActiveState()));
+        TmfXmlState state = fStatesMap.get(scenarioInfo.getActiveState());
+        if (state == null) {
+            /** FIXME: This logging should be replaced by something the user will see, this is XML debugging information! */
+            Activator.logError(NLS.bind(Messages.TmfXmlFsm_StateUndefined, scenarioInfo.getActiveState(), getId()));
+            return null;
+        }
         for (int i = 0; i < state.getTransitionList().size() && !matched; i++) {
             stateTransition = state.getTransitionList().get(i);
             matched = stateTransition.test(event, scenarioInfo, tests);
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/messages.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/messages.properties
new file mode 100644 (file)
index 0000000..42fa9d5
--- /dev/null
@@ -0,0 +1,10 @@
+###############################################################################
+# Copyright (c) 2014 École Polytechnique de Montréal
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+###############################################################################
+
+TmfXmlFsm_StateUndefined=The state "{0}" is not defined for FSM "{1}"
This page took 0.026217 seconds and 5 git commands to generate.