Add null-checks for Map.get()
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 25 May 2015 16:31:13 +0000 (12:31 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 13 Oct 2015 17:42:26 +0000 (13:42 -0400)
Map.get() can return null, and this can mean two different things:

1) The value associated with this key is 'null'.
2) There is no such key in this map.

Java 8 type annotations (Map<K, @NonNull V> for example) can cover
for the first case, but not the second! Map.get() can *always*
return null, no matter the map declaration. The enhanced null analysis
reveals that.

Many places in the code call Map.get() without null-checking, we can
fix these cases in advance. In many cases, this also exposed places
where iterating on map entries should have been done instead of
iterating on keys and doing a lookup.

Change-Id: I8b94a7ed7193f41479b3b0bc9b5990213b9718a3
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/52015
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
33 files changed:
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageXYViewer.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFTraceTest.java
ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java
ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java
ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/event/CtfTmfLostEventStatisticsTest.java
ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/internal/tmf/ctf/core/trace/iterator/CtfIteratorManager.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlPropertiesTest.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/stubs/org/eclipse/tracecompass/internal/lttng2/control/stubs/shells/LTTngToolsFileShell.java
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/perf/org/eclipse/tracecompass/lttng2/kernel/core/tests/perf/analysis/StatisticsAnalysisBenchmark.java
lttng/org.eclipse.tracecompass.lttng2.ust.ui/src/org/eclipse/tracecompass/internal/lttng2/ust/ui/views/memusage/MemoryUsageViewer.java
pcap/org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/stream/PacketStreamBuilder.java
pcap/org.eclipse.tracecompass.tmf.pcap.core/src/org/eclipse/tracecompass/internal/tmf/pcap/core/analysis/StreamListAnalysis.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlPresentationProvider.java
tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/analysis/TestRequirementAnalysis.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/component/TmfProviderManager.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/analysis/TmfAnalysisManager.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTrace.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/project/model/TmfTraceType.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statistics/TmfEventsStatistics.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimePreferences.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/dialogs/offset/OffsetDialog.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfProjectRegistry.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfTraceFolder.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/wizards/SelectTracesWizardPage.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterViewer.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/BasicFrame.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/Frame.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/GraphNode.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/core/Lifeline.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/uml2sd/preferences/SDViewPref.java

index e01cd738319aa662d78358b90fdcb25983f6695f..e1e1478c14219fc304563a70c709fe3abe4aa904 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.analysis.os.linux.ui.views.cpuusage;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -183,11 +185,13 @@ public class CpuUsageXYViewer extends TmfCommonXLineChartViewer {
 
                         if (entry.getKey().equals(stringSelectedThread)) {
                             /* This is the total cpu usage for a thread */
-                            fYValues.get(entry.getKey())[i] = (double) cpuEntry / (double) (time - prevTime) * 100;
+                            double[] key = checkNotNull(fYValues.get(entry.getKey()));
+                            key[i] = (double) cpuEntry / (double) (time - prevTime) * 100;
                         }
 
                     }
-                    fYValues.get(Messages.CpuUsageXYViewer_Total)[i] = (double) totalCpu / (double) (time - prevTime) * 100;
+                    double[] key = checkNotNull(fYValues.get(Messages.CpuUsageXYViewer_Total));
+                    key[i] = (double) totalCpu / (double) (time - prevTime) * 100;
                     prevTime = time;
                 }
                 for (Entry<String, double[]> entry : fYValues.entrySet()) {
index 90aa9139ba3ca32ae7b246f931b7ec7a688a2c04..48ab953a64222b363f0dd85aa635e2f51a152dd7 100644 (file)
@@ -372,6 +372,7 @@ public class CTFTraceTest {
         String key = "test";
         fixture.addEnvironmentVar(key, key);
         String result = fixture.getEnvironment().get(key);
+        assertNotNull(result);
         assertTrue(result.equals(key));
     }
 
index 3ff906ad427ffe155a41aeca109a133d2f6375ed..4b5262335524242f0d538a6a447f48e53639c77e 100644 (file)
@@ -239,7 +239,7 @@ public class VariantDeclaration extends Declaration {
                     return false;
                 }
                 IDeclaration field2 = other.fFields.get(field.getKey());
-                if (!field2.isBinaryEquivalent(field.getValue())) {
+                if ((field2 == null) || (!field2.isBinaryEquivalent(field.getValue()))) {
                     return false;
                 }
             }
index 9d82709e13cd247e4180beeda48d6dafa2dc578a..2ef8fec142e60aa8f98e41a5c995974657660443 100644 (file)
@@ -221,7 +221,11 @@ public class CTFTrace implements IDefinitionScope {
      * @return The list of event declarations
      */
     public Collection<IEventDeclaration> getEventDeclarations(Long streamId) {
-        return fStreams.get(streamId).getEventDeclarations();
+        CTFStream stream = fStreams.get(streamId);
+        if (stream == null) {
+            return null;
+        }
+        return stream.getEventDeclarations();
     }
 
     /**
@@ -798,14 +802,12 @@ public class CTFTrace implements IDefinitionScope {
      *             The file must exist
      */
     public void addStream(long id, File streamFile) throws CTFException {
-        CTFStream stream = null;
         final File file = streamFile;
         if (file == null) {
             throw new CTFException("cannot create a stream with no file"); //$NON-NLS-1$
         }
-        if (fStreams.containsKey(id)) {
-            stream = fStreams.get(id);
-        } else {
+        CTFStream stream = fStreams.get(id);
+        if (stream == null) {
             stream = new CTFStream(this);
             fStreams.put(id, stream);
         }
index a4436df9c965661d883a483ef34914fbfb843405..febe31ec5744e8337387764822bfe3bf37d1a157 100644 (file)
@@ -163,7 +163,8 @@ public class CtfTmfLostEventStatisticsTest {
     @Test
     public void testLostEventsTypesInRange() {
         Map<String, Long> eventsInRange = fStats.getEventTypesInRange(rangeStart, rangeEnd);
-        long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME);
-        assertEquals(365752L, lostEventsInRange);
+        Long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME);
+        assertNotNull(lostEventsInRange);
+        assertEquals(365752L, lostEventsInRange.longValue());
     }
 }
index fabde12231415c76c6aec14af6de319d71693a86..b580652350586b3d35d953b7564f526c0621fa26 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -181,7 +183,7 @@ public class CtfIteratorManager {
             final int pos = fRnd.nextInt(size);
             final CtfTmfContext victim = fRandomAccess.get(pos);
             fRandomAccess.set(pos, context);
-            CtfIterator elem = fMap.remove(victim);
+            CtfIterator elem = checkNotNull(fMap.remove(victim));
             if (elem.isClosed()) {
                 /*
                  * In case the iterator streams have been closed, we need to
index aaa4d64bae419f25d06303d0a10a5e143d910155..b528dbdd8c37c337786f5e54a5e95b8f6bac2672 100644 (file)
@@ -352,16 +352,19 @@ public class TraceControlPropertiesTest {
         //-------------------------------------------------------------------------
         event = (TraceEventComponent) domains[1].getChildren()[1].getChildren()[0];
         adapter = event.getAdapter(IPropertySource.class);
+        assertNotNull(adapter);
         eventSource = (TraceEventPropertySource) adapter;
         assertEquals("== TRACE_DEBUG_LINE", eventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_LOGLEVEL_PROPERTY_ID));
 
         event = (TraceEventComponent) domains[1].getChildren()[1].getChildren()[1];
         adapter = event.getAdapter(IPropertySource.class);
+        assertNotNull(adapter);
         eventSource = (TraceEventPropertySource) adapter;
         assertEquals("<= TRACE_INFO", eventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_LOGLEVEL_PROPERTY_ID));
 
         event = (TraceEventComponent) domains[1].getChildren()[1].getChildren()[2];
         adapter = event.getAdapter(IPropertySource.class);
+        assertNotNull(adapter);
         eventSource = (TraceEventPropertySource) adapter;
         assertEquals("TRACE_DEBUG_SYSTEM", eventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_LOGLEVEL_PROPERTY_ID));
 
index 5d6bf941a87584389e97b4d28d47dce8f34c19d9..391a4b831c60791e1a6afb58620a6498f39f76ae 100644 (file)
@@ -246,7 +246,7 @@ public class LTTngToolsFileShell extends TestCommandShell {
 
     @Override
     public synchronized ICommandResult executeCommand(ICommandInput command, IProgressMonitor monitor) throws ExecutionException {
-        Map<String, ICommandResult> commands = fScenarioMap.get(fScenario);
+        Map<String, ICommandResult> commands = checkNotNull(fScenarioMap.get(fScenario));
         String commandLine = command.toString();
         String fullCommand = commandLine;
 
index 9dc8c31337064f2fc2870e959b184f083c960a62..f1f3166b56825aba58cb06332ac7bca3de1edfea 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeTrue;
 
@@ -32,7 +34,6 @@ import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -125,7 +126,9 @@ public class StatisticsAnalysisBenchmark {
                  */
                 try {
                     for (Entry<String, Long> entry : testCases.entrySet()) {
-                        Assert.assertTrue(map.get(entry.getKey()).equals(entry.getValue()));
+                        Long value = map.get(entry.getKey());
+                        assertNotNull(value);
+                        assertTrue(value.equals(entry.getValue()));
                     }
                 } catch (NullPointerException e) {
                     fail(e.getMessage());
index a1694bbcd3152d1e3cf4d2252aa1524fa0b722f0..65bea9aae239c2815b2445d4437feb95f2cc9758 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.internal.lttng2.ust.ui.views.memusage;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -140,11 +142,13 @@ public class MemoryUsageViewer extends TmfCommonXLineChartViewer {
                     time = time > traceEnd ? traceEnd : time;
 
                     for (int quark : tidQuarks) {
+                        double[] values = checkNotNull(fYValues.get(quark));
                         try {
-                            yvalue = ss.querySingleState(time, fMemoryQuarks.get(quark)).getStateValue().unboxLong() / BYTES_TO_KB;
-                            fYValues.get(quark)[i] = yvalue;
+                            Integer memQuark = checkNotNull(fMemoryQuarks.get(quark));
+                            yvalue = ss.querySingleState(time, memQuark.intValue()).getStateValue().unboxLong() / BYTES_TO_KB;
+                            values[i] = yvalue;
                         } catch (TimeRangeException e) {
-                            fYValues.get(quark)[i] = 0;
+                            values[i] = 0;
                         }
                     }
                 }
index 60f2a793d91bfafe342823be872372881aa0114d..7cf9fe6bca7f9efa0506a884de84188873ef6da7 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.internal.pcap.core.stream;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.io.IOException;
 import java.nio.file.Path;
 import java.util.HashMap;
@@ -83,7 +85,7 @@ public class PacketStreamBuilder {
      */
     public synchronized @Nullable PacketStream getStream(ProtocolEndpoint endpointA, ProtocolEndpoint endpointB) {
         ProtocolEndpointPair set = new ProtocolEndpointPair(endpointA, endpointB);
-        int id = fIDs.get(set);
+        Integer id = checkNotNull(fIDs.get(set));
         return fStreams.get(id);
     }
 
@@ -113,12 +115,14 @@ public class PacketStreamBuilder {
             ProtocolEndpointPair endpointSet = new ProtocolEndpointPair(newPacket);
             if (!fIDs.containsKey(endpointSet)) {
                 fIDs.put(endpointSet, fCurrentId);
-                fStreams.put(fCurrentId, new PacketStream(fProtocol, fCurrentId, endpointSet));
-                fStreams.get(fCurrentId).add(packet);
+
+                PacketStream stream = new PacketStream(fProtocol, fCurrentId, endpointSet);
+                stream.add(packet);
+                fStreams.put(fCurrentId, stream);
                 fCurrentId++;
             } else {
                 Integer id = fIDs.get(endpointSet);
-                fStreams.get(id).add(packet);
+                checkNotNull(fStreams.get(id)).add(packet);
             }
         }
         return;
index 7978bda64b5dfd9288824bc7495efb01a1d8ea82..07e216a3da561532dca16583623fbccf1e4d80ec 100644 (file)
@@ -112,8 +112,8 @@ public class StreamListAnalysis extends TmfAbstractAnalysisModule {
                     return;
                 }
                 PcapEvent event = (PcapEvent) data;
-                for (TmfPcapProtocol protocol : fBuilders.keySet()) {
-                    fBuilders.get(protocol).addEventToStream(event);
+                for (Map.Entry<TmfPcapProtocol, TmfPacketStreamBuilder> entry : fBuilders.entrySet()) {
+                    entry.getValue().addEventToStream(event);
                 }
 
             }
index a25103168374c614bc399d75592d7e3eceecc7a9..17ef228453fa3fce35604603155346061cb3c07f 100644 (file)
@@ -292,16 +292,18 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
                     time = time > traceEnd ? traceEnd : time;
 
                     for (int quark : quarks) {
+                        SeriesData data = checkNotNull(fSeriesData.get(quark));
                         try {
-                            yvalue = ss.querySingleState(time, fSeriesData.get(quark).getDisplayQuark()).getStateValue().unboxLong();
-                            fSeriesData.get(quark).setYValue(i, yvalue);
+                            yvalue = ss.querySingleState(time, data.getDisplayQuark()).getStateValue().unboxLong();
+                            data.setYValue(i, yvalue);
                         } catch (TimeRangeException e) {
-                            fSeriesData.get(quark).setYValue(i, 0);
+                            data.setYValue(i, 0);
                         }
                     }
                 }
                 for (int quark : quarks) {
-                    setSeries(fSeriesData.get(quark).getSeriesName(), fSeriesData.get(quark).getYValues());
+                    SeriesData data = checkNotNull(fSeriesData.get(quark));
+                    setSeries(data.getSeriesName(), data.getYValues());
                 }
                 updateDisplay();
             } catch (AttributeNotFoundException | StateValueTypeException e) {
index 48e94306b257aecb6bf9cc0ffe84de90691aa169..8c88a9456ebfc57f0a74bf6681315ba5dad460ac 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -87,8 +89,8 @@ public class XmlPresentationProvider extends TimeGraphPresentationProvider {
             int value = tcEvent.getValue();
 
             if (entry.getType() == EntryDisplayType.DISPLAY) {
-                Integer index = stateIndex.get(value);
-                String rgb = stateValues.get(index).getStateString();
+                Integer index = checkNotNull(stateIndex.get(value));
+                String rgb = stateValues.get(index.intValue()).getStateString();
                 return rgb;
             }
             return null;
index 33a37ca56e500d90f2a3d61f294f68798241d8d2..7edc99f03fcefa09a2b40c75b4ce100dcac21271 100644 (file)
@@ -69,15 +69,17 @@ public class TestRequirementAnalysis extends TmfAbstractAnalysisModule {
         Map<String, TmfAnalysisRequirement> requirements = new HashMap<>();
 
         /* Event type requirement and values */
-        requirements.put(EVENT_TYPE, new TmfAnalysisRequirement(EVENT_TYPE));
-        requirements.get(EVENT_TYPE).addValue(EXIT_SYSCALL, ValuePriorityLevel.MANDATORY);
-        requirements.get(EVENT_TYPE).addValue(SCHED_SWITCH, ValuePriorityLevel.MANDATORY);
-        requirements.get(EVENT_TYPE).addValue(SCHED_WAKEUP, ValuePriorityLevel.MANDATORY);
+        TmfAnalysisRequirement eventReqs = new TmfAnalysisRequirement(EVENT_TYPE);
+        eventReqs.addValue(EXIT_SYSCALL, ValuePriorityLevel.MANDATORY);
+        eventReqs.addValue(SCHED_SWITCH, ValuePriorityLevel.MANDATORY);
+        eventReqs.addValue(SCHED_WAKEUP, ValuePriorityLevel.MANDATORY);
+        requirements.put(EVENT_TYPE, eventReqs);
 
         /* Field type requirement and values */
-        requirements.put(FIELD_TYPE, new TmfAnalysisRequirement(FIELD_TYPE));
-        requirements.get(FIELD_TYPE).addValue(PID, ValuePriorityLevel.MANDATORY);
-        requirements.get(FIELD_TYPE).addValue(TID, ValuePriorityLevel.MANDATORY);
+        TmfAnalysisRequirement fieldReqs = new TmfAnalysisRequirement(FIELD_TYPE);
+        fieldReqs.addValue(PID, ValuePriorityLevel.MANDATORY);
+        fieldReqs.addValue(TID, ValuePriorityLevel.MANDATORY);
+        requirements.put(FIELD_TYPE, fieldReqs);
 
         @SuppressWarnings("null")
         @NonNull Collection<TmfAnalysisRequirement> values = requirements.values();
index b4a479e2d5bb0201f0a6a9fd4492e72f830c2d0c..a5a74fa2635ba2b176741a112f24749841a0c1a3 100644 (file)
@@ -50,11 +50,13 @@ public class TmfProviderManager {
      * @param provider
      *            The data provider
      */
-    public static <T extends ITmfEvent> void register(Class<T> eventType, TmfEventProvider provider) {
-        if (fProviders.get(eventType) == null) {
-            fProviders.put(eventType, new ArrayList<TmfEventProvider>());
+    public static synchronized <T extends ITmfEvent> void register(Class<T> eventType, TmfEventProvider provider) {
+        List<TmfEventProvider> typeProviders = fProviders.get(eventType);
+        if (typeProviders == null) {
+            typeProviders = new ArrayList<>();
+            fProviders.put(eventType, typeProviders);
         }
-        fProviders.get(eventType).add(provider);
+        typeProviders.add(provider);
     }
 
     /**
@@ -65,7 +67,7 @@ public class TmfProviderManager {
      * @param provider
      *            The data provider
      */
-    public static <T extends ITmfEvent> void deregister(Class<T> eventType, TmfEventProvider provider) {
+    public static synchronized <T extends ITmfEvent> void deregister(Class<T> eventType, TmfEventProvider provider) {
         List<TmfEventProvider> list = fProviders.get(eventType);
         if (list != null) {
             list.remove(provider);
index df59aaeeeba0d428a06150c5c8acf55779927b94..f284f5fff06eab42984387cf040a33c17cd8e1ea 100644 (file)
@@ -162,7 +162,8 @@ public class TmfAnalysisManager {
             if (!fParameterProviders.containsKey(analysisId)) {
                 fParameterProviders.put(analysisId, new ArrayList<Class<? extends IAnalysisParameterProvider>>());
             }
-            fParameterProviders.get(analysisId).add(paramProvider);
+            /* We checked via containsKey() above, get() should not return null */
+            checkNotNull(fParameterProviders.get(analysisId)).add(paramProvider);
         }
     }
 
@@ -181,14 +182,16 @@ public class TmfAnalysisManager {
             if (!fParameterProviders.containsKey(module.getId())) {
                 return providerList;
             }
-            for (Class<? extends IAnalysisParameterProvider> providerClass : fParameterProviders.get(module.getId())) {
+            /* We checked  via containsKey, get() should not return null */
+            List<Class<? extends IAnalysisParameterProvider>> parameterProviders = checkNotNull(fParameterProviders.get(module.getId()));
+            for (Class<? extends IAnalysisParameterProvider> providerClass : parameterProviders) {
                 try {
                     IAnalysisParameterProvider provider = fParamProviderInstances.get(providerClass);
                     if (provider == null) {
                         provider = providerClass.newInstance();
                         fParamProviderInstances.put(providerClass, provider);
                     }
-                    if (provider != null && provider.appliesToTrace(trace)) {
+                    if (provider.appliesToTrace(trace)) {
                         providerList.add(provider);
                     }
                 } catch (IllegalArgumentException | SecurityException | InstantiationException | IllegalAccessException e) {
index b8f46052b4029a220204a2cfac0c3fb9e5f60368..207408d78b16a140f3c5fedbc68231d1d1594a81 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.tmf.core.parsers.custom;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -295,7 +297,7 @@ public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexabl
                         }
                     }
                 } else {
-                    if (countMap.get(currentInput) >= currentInput.getMinCount()) {
+                    if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMinCount()) {
                         final List<InputLine> nextInputs = currentInput.getNextInputs(countMap);
                         if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {
                             for (final InputLine input : getFirstLines()) {
@@ -318,7 +320,7 @@ public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexabl
                                 if (countMap.get(currentInput) == null) {
                                     countMap.put(currentInput, 1);
                                 } else {
-                                    countMap.put(currentInput, countMap.get(currentInput) + 1);
+                                    countMap.put(currentInput, checkNotNull(countMap.get(currentInput)) + 1);
                                 }
                                 Iterator<InputLine> iter = countMap.keySet().iterator();
                                 while (iter.hasNext()) {
@@ -330,7 +332,7 @@ public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexabl
                                 if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
                                     currentInput = currentInput.childrenInputs.get(0);
                                     countMap.put(currentInput, 0);
-                                } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+                                } else if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMaxCount()) {
                                     if (currentInput.getNextInputs(countMap).size() > 0) {
                                         currentInput = currentInput.getNextInputs(countMap).get(0);
                                         if (countMap.get(currentInput) == null) {
@@ -356,11 +358,11 @@ public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexabl
                         final Matcher matcher = currentInput.getPattern().matcher(line);
                         if (matcher.matches()) {
                             event.processGroups(currentInput, matcher);
-                            countMap.put(currentInput, countMap.get(currentInput) + 1);
+                            countMap.put(currentInput, checkNotNull(countMap.get(currentInput)) + 1);
                             if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
                                 currentInput = currentInput.childrenInputs.get(0);
                                 countMap.put(currentInput, 0);
-                            } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+                            } else if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMaxCount()) {
                                 if (currentInput.getNextInputs(countMap).size() > 0) {
                                     currentInput = currentInput.getNextInputs(countMap).get(0);
                                     if (countMap.get(currentInput) == null) {
index f2fa3e019c8bcdb0ed1852b23f09f1bcbc1251ce..13a159feb267307f3d11d2dfde714681c7b8b07a 100644 (file)
@@ -320,7 +320,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
                 next = next.nextInput;
             }
             if (parentInput != null && parentInput.level > 0) {
-                int parentCount = countMap.get(parentInput);
+                int parentCount = checkNotNull(countMap.get(parentInput));
                 if (parentCount < parentInput.getMaxCount()) {
                     nextInputs.add(parentInput);
                 }
index 861d66a47f056b40b5c4e125dfabb9ec7adcb728..e32180ca838c2dd21d0733fa509ed4289c40503e 100644 (file)
@@ -410,8 +410,8 @@ public final class TmfTraceType {
      */
     public static List<String> getTraceCategories() {
         List<String> categoryNames = new ArrayList<>();
-        for (String key : TRACE_TYPES.keySet()) {
-            final String categoryName = TRACE_TYPES.get(key).getCategoryName();
+        for (Map.Entry<String, TraceTypeHelper> entry : TRACE_TYPES.entrySet()) {
+            final String categoryName = entry.getValue().getCategoryName();
             if (!categoryNames.contains(categoryName)) {
                 categoryNames.add(categoryName);
             }
index e7cbb71f2d622180a699fe44a5a1c762714ed226..4282b476d0fb720061c838762d68377f64e421bc 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.tmf.core.statistics;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -214,7 +216,7 @@ public class TmfEventsStatistics implements ITmfStatistics {
 
         private void incrementStats(String key, long count) {
             if (stats.containsKey(key)) {
-                long curValue = stats.get(key);
+                long curValue = checkNotNull(stats.get(key));
                 stats.put(key, curValue + count);
             } else {
                 stats.put(key, count);
@@ -275,7 +277,7 @@ public class TmfEventsStatistics implements ITmfStatistics {
         }
 
         private void incrementValue(Long key) {
-            long value = results.get(key);
+            long value = checkNotNull(results.get(key));
             value++;
             results.put(key, value);
         }
index 2a1ca50a95d630c61f8280515d8e78d583294463..553d5cb09a3ed153a6e844a35c84ec18eb4a5416 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.tmf.core.timestamp;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -157,7 +159,7 @@ public final class TmfTimePreferences {
     }
 
     private static String computeSubSecFormat(Map<String, String> prefsMap) {
-        String sSecFormat = prefsMap.get(ITmfTimePreferencesConstants.SUBSEC);
+        String sSecFormat = checkNotNull(prefsMap.get(ITmfTimePreferencesConstants.SUBSEC));
         String sSecFieldSep = prefsMap.get(ITmfTimePreferencesConstants.SSEC_DELIMITER);
         String ssecFmt = sSecFormat.replaceAll(" ", sSecFieldSep); //$NON-NLS-1$
         return ssecFmt;
index c29c013f2908a9bcdc2f32dd5d3efd4655f8afae..683823c2a037cb5f9759833cb97fb4b599fa512d 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.internal.tmf.ui.parsers.wizards;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
@@ -733,7 +735,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                                     }
                                 }
                             } else {
-                                if (countMap.get(currentInput) >= currentInput.getMinCount()) {
+                                if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMinCount()) {
                                     List<InputLine> nextInputs = currentInput.getNextInputs(countMap);
                                     if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {
                                         for (InputLine input : definition.inputs) {
@@ -761,7 +763,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                                             if (countMap.get(currentInput) == null) {
                                                 countMap.put(currentInput, 1);
                                             } else {
-                                                countMap.put(currentInput, countMap.get(currentInput) + 1);
+                                                countMap.put(currentInput, checkNotNull(countMap.get(currentInput)) + 1);
                                             }
                                             Iterator<InputLine> iter = countMap.keySet().iterator();
                                             while (iter.hasNext()) {
@@ -774,7 +776,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                                                 currentInput = currentInput.childrenInputs.get(0);
                                                 countMap.put(currentInput, 0);
                                             } else {
-                                                if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+                                                if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMaxCount()) {
                                                     if (currentInput.getNextInputs(countMap).size() > 0) {
                                                         currentInput = currentInput.getNextInputs(countMap).get(0);
                                                         if (countMap.get(currentInput) == null) {
@@ -807,12 +809,12 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                                         inputText.setStyleRange(new StyleRange(rawPos, length,
                                                 COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));
                                         updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);
-                                        countMap.put(currentInput, countMap.get(currentInput) + 1);
+                                        countMap.put(currentInput, checkNotNull(countMap.get(currentInput)) + 1);
                                         if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
                                             currentInput = currentInput.childrenInputs.get(0);
                                             countMap.put(currentInput, 0);
                                         } else {
-                                            if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+                                            if (checkNotNull(countMap.get(currentInput)) >= currentInput.getMaxCount()) {
                                                 if (currentInput.getNextInputs(countMap).size() > 0) {
                                                     currentInput = currentInput.getNextInputs(countMap).get(0);
                                                     if (countMap.get(currentInput) == null) {
index 7246c2d37c9b93547dbe3803e84144c1741312a4..f1f4569c5379acc50117d3e7db1980e88e8d06a1 100644 (file)
@@ -149,10 +149,11 @@ public class OffsetDialog extends Dialog {
 
         @Override
         protected Object getValue(Object element) {
-            if (map.get(element) == null) {
+            ITmfTimestamp ts = map.get(element);
+            if (ts == null) {
                 return ""; //$NON-NLS-1$
             }
-            return TIME_FORMAT.format(map.get(element).normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
+            return TIME_FORMAT.format(ts.normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
         }
     }
 
@@ -193,10 +194,11 @@ public class OffsetDialog extends Dialog {
 
         @Override
         protected Object getValue(Object element) {
-            if (fOffsetMap.get(element) == 0) {
+            Long offset = fOffsetMap.get(element);
+            if (offset == null || offset == 0) {
                 return ""; //$NON-NLS-1$
             }
-            return OFFSET_FORMAT.format((long) fOffsetMap.get(element));
+            return OFFSET_FORMAT.format(offset.longValue());
         }
     }
 
@@ -345,10 +347,11 @@ public class OffsetDialog extends Dialog {
         column.setLabelProvider(new ColumnLabelProvider() {
             @Override
             public String getText(Object element) {
-                if (fOffsetMap.get(element) != 0) {
-                    return super.getText(OFFSET_FORMAT.format((long) fOffsetMap.get(element)));
+                Long offset = fOffsetMap.get(element);
+                if (offset == null || offset == 0) {
+                    return ""; //$NON-NLS-1$
                 }
-                return ""; //$NON-NLS-1$
+                return super.getText(OFFSET_FORMAT.format(offset.longValue()));
             }
         });
         column.setEditingSupport(new OffsetEditingSupport(fViewer.getViewer(), textCellEditor));
index 96417a9b52b4a605a1cf01981b2674bc4951e254..14cfa4199acc543e6cb378e2d2f7202dab30a5cc 100644 (file)
@@ -76,8 +76,8 @@ public class TmfProjectRegistry implements IResourceChangeListener {
     public static synchronized TmfProjectElement getProject(IProject project, boolean force) {
         TmfProjectElement element = registry.get(project);
         if (element == null && force) {
-            registry.put(project, new TmfProjectElement(project.getName(), project, null));
-            element = registry.get(project);
+            element = new TmfProjectElement(project.getName(), project, null);
+            registry.put(project, element);
             // force the model to be populated
             element.refreshChildren();
         }
index 01e7e3e835a4f95a7c91d7b746d1d822f97a2647..4a5dc45e5b141c88a4f682a2b4c7b7b8a508a6f7 100644 (file)
@@ -123,7 +123,9 @@ public class TmfTraceFolder extends TmfProjectModelElement implements IPropertyS
                 } else {
                     childrenMap.remove(name);
                 }
-                ((TmfProjectModelElement) element).refreshChildren();
+                if (element != null) {
+                    ((TmfProjectModelElement) element).refreshChildren();
+                }
             }
         } catch (CoreException e) {
         }
index 276d235c83683842afba3ffddab48c5789cfce5d..e22c5da36cda5483700e7adc8bdcf702471bca8b 100644 (file)
@@ -417,10 +417,9 @@ public class SelectTracesWizardPage extends WizardPage {
 
                 // Remove traces that were unchecked (thus left in
                 // fPreviousTraces)
-                keys = fPreviousTraces.keySet();
-                for (String key : keys) {
+                for (Map.Entry<String, TmfTraceElement> entry : fPreviousTraces.entrySet()) {
                     ModalContext.checkCanceled(progressMonitor);
-                    TmfTraceElement trace = fPreviousTraces.get(key);
+                    TmfTraceElement trace = entry.getValue();
                     subMonitor.setTaskName(Messages.SelectTracesWizardPage_TraceRemovalTask + " " + trace.getElementPath()); //$NON-NLS-1$
 
                     try {
index fe4a55a4d4a1e6408e82d68c0329920e243e9706..205fce44fb0ee0aa5700af23d6b753b0af84c7d1 100644 (file)
@@ -14,6 +14,8 @@
 
 package org.eclipse.tracecompass.tmf.ui.views.filter;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -718,7 +720,7 @@ class FilterViewer extends Composite {
             fTypeCombo.addModifyListener(new ModifyListener() {
                 @Override
                 public void modifyText(ModifyEvent e) {
-                    TraceTypeHelper helper = fTraceTypeMap.get(fTypeCombo.getText());
+                    TraceTypeHelper helper = checkNotNull(fTraceTypeMap.get(fTypeCombo.getText()));
                     fNode.setTraceTypeId(helper.getTraceTypeId());
                     fNode.setTraceClass(helper.getTraceClass());
                     fNode.setName(fTypeCombo.getText());
index 2f7272dea600f6eee7f3075c6c06b32a2bfbe5af..930a5f978477850596de86608ef9f5309600b697 100755 (executable)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.tmf.ui.views.uml2sd.core;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -553,7 +555,7 @@ public class BasicFrame extends GraphNode {
         List<SDTimeEvent> timeArray = new ArrayList<>();
         while (it.hasNext()) {
             String nodeType = it.next();
-            List<GraphNode> list = getNodeMap().get(nodeType);
+            List<GraphNode> list = checkNotNull(getNodeMap().get(nodeType));
             for (int i = 0; i < list.size(); i++) {
                 Object timedNode = list.get(i);
                 if ((timedNode instanceof ITimeRange) && ((ITimeRange) timedNode).hasTimeInfo()) {
index 5e69d6fa2d648473de98ce2ef3700a6fbc5e9cfd..6dd290d2e545e026afd05e1cd35dd6ddc8c62d06 100755 (executable)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.tmf.ui.views.uml2sd.core;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -292,10 +294,9 @@ public class Frame extends BasicFrame {
     public int getFirstVisibleLifeline() {
         if (!hasChildren()) {
             return 0;
-        } else if (getIndexes().get(Lifeline.LIFELINE_TAG) != null) {
-            return getIndexes().get(Lifeline.LIFELINE_TAG).intValue();
         }
-        return 0;
+        Integer ret = getIndexes().get(Lifeline.LIFELINE_TAG);
+        return (ret == null ? 0 : ret.intValue());
     }
 
     /**
@@ -306,10 +307,9 @@ public class Frame extends BasicFrame {
     public int getFirstVisibleSyncMessage() {
         if (!hasChildren()) {
             return 0;
-        } else if (getIndexes().get(SyncMessage.SYNC_MESS_TAG) != null) {
-            return getIndexes().get(SyncMessage.SYNC_MESS_TAG).intValue();
         }
-        return 0;
+        Integer ret = getIndexes().get(SyncMessage.SYNC_MESS_TAG);
+        return (ret == null ? 0 : ret.intValue());
     }
 
     /**
@@ -320,10 +320,9 @@ public class Frame extends BasicFrame {
     public int getFirstVisibleSyncMessageReturn() {
         if (!hasChildren()) {
             return 0;
-        } else if (getIndexes().get(SyncMessageReturn.SYNC_MESS_RET_TAG) != null) {
-            return getIndexes().get(SyncMessageReturn.SYNC_MESS_RET_TAG).intValue();
         }
-        return 0;
+        Integer ret = getIndexes().get(SyncMessageReturn.SYNC_MESS_RET_TAG);
+        return (ret == null ? 0 : ret.intValue());
     }
 
     /**
@@ -334,10 +333,9 @@ public class Frame extends BasicFrame {
     public int getFirstVisibleAsyncMessage() {
         if (!hasChildren()) {
             return 0;
-        } else if (getIndexes().get(AsyncMessage.ASYNC_MESS_TAG) != null) {
-            return getIndexes().get(AsyncMessage.ASYNC_MESS_TAG).intValue();
         }
-        return 0;
+        Integer ret = getIndexes().get(AsyncMessage.ASYNC_MESS_TAG);
+        return (ret == null ? 0 : ret.intValue());
     }
 
     /**
@@ -348,10 +346,9 @@ public class Frame extends BasicFrame {
     public int getFirstVisibleAsyncMessageReturn() {
         if (!hasChildren()) {
             return 0;
-        } else if (getIndexes().get(AsyncMessageReturn.ASYNC_MESS_RET_TAG) != null) {
-            return getIndexes().get(AsyncMessageReturn.ASYNC_MESS_RET_TAG).intValue();
         }
-        return 0;
+        Integer ret = getIndexes().get(AsyncMessageReturn.ASYNC_MESS_RET_TAG);
+        return (ret == null ? 0 : ret.intValue());
     }
 
     /**
@@ -644,9 +641,10 @@ public class Frame extends BasicFrame {
         if (getIndexes().size() == 0) {
             return;
         }
-        int lifeLineDrawIndex = getIndexes().get(Lifeline.LIFELINE_TAG).intValue();
-        for (int i = lifeLineDrawIndex; i < getNodeMap().get(Lifeline.LIFELINE_TAG).size(); i = i + lifelineArryStep) {
-            Lifeline toDraw = (Lifeline) getNodeMap().get(Lifeline.LIFELINE_TAG).get(i);
+        int lifeLineDrawIndex = checkNotNull(getIndexes().get(Lifeline.LIFELINE_TAG)).intValue();
+        List<GraphNode> nodeList = checkNotNull(getNodeMap().get(Lifeline.LIFELINE_TAG));
+        for (int i = lifeLineDrawIndex; i < nodeList.size(); i = i + lifelineArryStep) {
+            Lifeline toDraw = (Lifeline) nodeList.get(i);
             if (toDraw.getX() - Metrics.LIFELINE_SPACING / 2 > context.getContentsX() + context.getVisibleWidth()) {
                 break;
             }
@@ -691,8 +689,9 @@ public class Frame extends BasicFrame {
         List<SDTimeEvent> timeArray = super.buildTimeArray();
         fExecutionOccurrencesWithTime = null;
         if (getLifelines() != null) {
-            for (int i = 0; i < getNodeMap().get(Lifeline.LIFELINE_TAG).size(); i++) {
-                Lifeline lifeline = (Lifeline) getNodeMap().get(Lifeline.LIFELINE_TAG).get(i);
+            List<GraphNode> nodeList = checkNotNull(getNodeMap().get(Lifeline.LIFELINE_TAG));
+            for (int i = 0; i < nodeList.size(); i++) {
+                Lifeline lifeline = (Lifeline) nodeList.get(i);
                 if (lifeline.hasTimeInfo() && lifeline.getExecutions() != null) {
                     for (Iterator<GraphNode> j = lifeline.getExecutions().iterator(); j.hasNext();) {
                         GraphNode o = j.next();
index d7a2db9460079c1666c64157129239ef4643b91f..965da7e142373a0ab67605d9df0e23c700f211ed 100755 (executable)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.tmf.ui.views.uml2sd.core;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
@@ -375,7 +377,7 @@ public abstract class GraphNode {
         GraphNode node = null;
         for (Map.Entry<String, List<GraphNode>> entry : fNodes.entrySet()) {
             List<GraphNode> list = entry.getValue();
-            int index = fIndexes.get(entry.getKey()).intValue();
+            int index = checkNotNull(fIndexes.get(entry.getKey())).intValue();
             node = getNodeFromListAt(x, y, list, index);
             if (toReturn == null) {
                 toReturn = node;
@@ -512,8 +514,7 @@ public abstract class GraphNode {
         for (Map.Entry<String, List<GraphNode>> entry : fNodes.entrySet()) {
             String nodeType = entry.getKey();
             int direction = 1;
-            int drawIndex = fIndexes.get(nodeType).intValue();
-
+            int drawIndex = checkNotNull(fIndexes.get(nodeType)).intValue();
             if ((entry.getValue() != null) && (entry.getValue().size() > 1)) {
                 if (entry.getValue().get(drawIndex).positiveDistanceToPoint(x, y)) {
                     direction = -1;
@@ -523,11 +524,12 @@ public abstract class GraphNode {
                     direction = 1;
                 }
 
-                if ((direction == -1) && (fBackwardNodes.get(nodeType) != null)) {
+                List<GraphNode> nodes = fBackwardNodes.get(nodeType);
+                if ((direction == -1) && (nodes != null)) {
                     GraphNode currentNode = entry.getValue().get(drawIndex);
-                    drawIndex = Arrays.binarySearch(fBackwardNodes.get(nodeType).toArray(new GraphNode[fBackwardNodes.get(nodeType).size()]),
+                    drawIndex = Arrays.binarySearch(nodes.toArray(new GraphNode[nodes.size()]),
                             entry.getValue().get(drawIndex), currentNode.getBackComparator());
-                    entry.setValue(fBackwardNodes.get(nodeType));
+                    entry.setValue(nodes);
                     if (drawIndex < 0) {
                         drawIndex = 0;
                         direction = 1;
@@ -585,9 +587,9 @@ public abstract class GraphNode {
 
                 entry.setValue(fForwardNodes.get(nodeType));
                 if ((fBackwardNodes.get(nodeType) != null) && (direction == -1)) {
-                    int index = fIndexes.get(nodeType).intValue();
+                    int index = checkNotNull(fIndexes.get(nodeType)).intValue();
                     List<GraphNode> list = entry.getValue();
-                    List<GraphNode> backList = fBackwardNodes.get(nodeType);
+                    List<GraphNode> backList = checkNotNull(fBackwardNodes.get(nodeType));
                     GraphNode currentNode = (backList.get(index));
                     if (index > 0) {
                         index = Arrays.binarySearch(list.toArray(new GraphNode[list.size()]), backList.get(index), currentNode.getComparator());
@@ -635,8 +637,9 @@ public abstract class GraphNode {
             String nodeType = entry.getKey();
             boolean sort = entry.getValue().booleanValue();
             if (sort) {
-                GraphNode[] temp = fForwardNodes.get(nodeType).toArray(new GraphNode[fForwardNodes.get(nodeType).size()]);
-                GraphNode node = fNodes.get(nodeType).get(0);
+                List<GraphNode> forwardNodes = checkNotNull(fForwardNodes.get(nodeType));
+                GraphNode[] temp = forwardNodes.toArray(new GraphNode[forwardNodes.size()]);
+                GraphNode node = checkNotNull(fNodes.get(nodeType)).get(0);
                 Arrays.sort(temp, node.getComparator());
                 entry.setValue(Boolean.FALSE);
                 fNodes.put(nodeType, Arrays.asList(temp));
@@ -651,8 +654,9 @@ public abstract class GraphNode {
             String nodeType = entry.getKey();
             boolean sort = entry.getValue().booleanValue();
             if (sort) {
-                GraphNode[] temp = fBackwardNodes.get(nodeType).toArray(new GraphNode[fBackwardNodes.get(nodeType).size()]);
-                GraphNode node = fNodes.get(nodeType).get(0);
+                List<GraphNode> backwardNodes = checkNotNull(fBackwardNodes.get(nodeType));
+                GraphNode[] temp = backwardNodes.toArray(new GraphNode[backwardNodes.size()]);
+                GraphNode node = checkNotNull(fNodes.get(nodeType)).get(0);
                 Arrays.sort(temp, node.getBackComparator());
                 entry.setValue(Boolean.FALSE);
                 fBackwardNodes.put(nodeType, Arrays.asList(temp));
@@ -676,9 +680,9 @@ public abstract class GraphNode {
         while (it3.hasNext()) {
             count = 0;
             Object nodeType = it3.next();
-            GraphNode node = fNodes.get(nodeType).get(0);
+            GraphNode node = checkNotNull(fNodes.get(nodeType)).get(0);
             context.setFont(SDViewPref.getInstance().getFont(node.fPrefId));
-            int index = fIndexes.get(nodeType).intValue();
+            int index = checkNotNull(fIndexes.get(nodeType)).intValue();
             count = drawNodes(context, fNodes.get(nodeType), index, arrayStep);
             if (TmfUiTracer.isDisplayTraced()) {
                 TmfUiTracer.traceDisplay(count + " " + nodeType + " drawn, starting from index " + index + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
index 21fc6600dfd6b43bbb54c611f3d5ac78d7ef65b1..7bc1bbcae508b72b320f746fecd785dead971010 100755 (executable)
@@ -147,10 +147,8 @@ public class Lifeline extends GraphNode {
         if (!hasChildren()) {
             return 0;
         }
-        if (getIndexes().get(BasicExecutionOccurrence.EXEC_OCC_TAG) != null) {
-            return getIndexes().get(BasicExecutionOccurrence.EXEC_OCC_TAG).intValue();
-        }
-        return 0;
+        Integer ret = getIndexes().get(BasicExecutionOccurrence.EXEC_OCC_TAG);
+        return (ret == null ? 0 : ret.intValue());
     }
 
     /**
index 593907b431bf168365ffba911083c0d456a90b9e..cb0119359cdc4269e00a56fb65a4f0bfd6f62025 100755 (executable)
@@ -361,32 +361,36 @@ public class SDViewPref implements ISDPreferences, IPropertyChangeListener {
 
         for (int i = 0; i < FONT_LIST.length; i++) {
             FontData fontData = PreferenceConverter.getFontData(fPrefStore, FONT_LIST[i]);
-            if (fFontPref.get(FONT_LIST[i]) != null) {
-                fFontPref.get(FONT_LIST[i]).dispose();
+            IFont font = fFontPref.get(FONT_LIST[i]);
+            if (font != null) {
+                font.dispose();
             }
             fFontPref.put(FONT_LIST[i], new FontImpl(display, fontData));
         }
 
         for (int i = 0; i < PREF_BACK_COLOR_LIST.length; i++) {
             RGB rgb = PreferenceConverter.getColor(fPrefStore, PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX);
-            if (fBackColorPref.get(PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX) != null) {
-                fBackColorPref.get(PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX).dispose();
+            IColor color = fBackColorPref.get(PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX);
+            if (color != null) {
+                color.dispose();
             }
             fBackColorPref.put(PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue));
         }
 
         for (int i = 0; i < PREF_FORE_COLOR_LIST.length; i++) {
             RGB rgb = PreferenceConverter.getColor(fPrefStore, PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX);
-            if (fForeColorPref.get(PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX) != null) {
-                fForeColorPref.get(PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX).dispose();
+            IColor color = fForeColorPref.get(PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX);
+            if (color != null) {
+                color.dispose();
             }
             fForeColorPref.put(PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue));
         }
 
         for (int i = 0; i < PREF_TEXT_COLOR_LIST.length; i++) {
             RGB rgb = PreferenceConverter.getColor(fPrefStore, PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX);
-            if (fTextColorPref.get(PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX) != null) {
-                fTextColorPref.get(PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX).dispose();
+            IColor color = fTextColorPref.get(PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX);
+            if (color != null) {
+                color.dispose();
             }
             fTextColorPref.put(PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue));
         }
This page took 0.049214 seconds and 5 git commands to generate.