From: Geneviève Bastien Date: Wed, 4 May 2016 19:55:00 +0000 (-0400) Subject: xml: Replace a checkNotNull by a message when state undefined X-Git-Url: http://git.efficios.com/?p=deliverable%2Ftracecompass.git;a=commitdiff_plain;h=146e73f62256bd81641de5b0d7e6e9d553777d00 xml: Replace a checkNotNull by a message when state undefined 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 Reviewed-on: https://git.eclipse.org/r/72080 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam --- 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 index 0000000000..54e55f29cc --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/Messages.java @@ -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() { + } +} diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java index 00e343d0e4..4d8bd302a2 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java @@ -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 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 index 0000000000..42fa9d5a5b --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/messages.properties @@ -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}"