[eclipse-cdt/f20] Fix rhbz#1138994 (NPE in Formatter preferences page)

Jeff Johnston jjohnstn at fedoraproject.org
Tue Sep 9 21:48:46 UTC 2014


commit e6ad040800a415a4351ef16248d14894e5bba7d4
Author: Jeff Johnston <jjohnstn at redhat.com>
Date:   Tue Sep 9 17:48:21 2014 -0400

    Fix rhbz#1138994 (NPE in Formatter preferences page)

 eclipse-cdt-custom-formatter.patch |  129 ++++++++++++++++++++++++++++++++++++
 eclipse-cdt.spec                   |    9 ++-
 2 files changed, 137 insertions(+), 1 deletions(-)
---
diff --git a/eclipse-cdt-custom-formatter.patch b/eclipse-cdt-custom-formatter.patch
new file mode 100644
index 0000000..f72018b
--- /dev/null
+++ b/eclipse-cdt-custom-formatter.patch
@@ -0,0 +1,129 @@
+diff -up ./core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java.fix ./core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java
+--- ./core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java.fix	2014-09-09 14:46:41.566990364 -0400
++++ ./core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java	2014-09-09 14:46:50.663142154 -0400
+@@ -1,5 +1,5 @@
+ /*******************************************************************************
+- * Copyright (c) 2000, 2013 QNX Software Systems and others.
++ * Copyright (c) 2000, 2014 QNX Software Systems and others.
+  * 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
+@@ -13,7 +13,6 @@
+ package org.eclipse.cdt.internal.ui.preferences.formatter;
+ 
+ import java.util.HashMap;
+-import java.util.Iterator;
+ import java.util.Map;
+ import java.util.Observable;
+ 
+@@ -68,7 +67,7 @@ public class CustomCodeFormatterBlock ex
+ 		fPrefs= scope.getNode(CCorePlugin.PLUGIN_ID);
+ 		fDefaultFormatterId= defaults.get(CCorePreferenceConstants.CODE_FORMATTER, null);
+ 		if (fDefaultFormatterId == null) {
+-			// backward compatibility: use UI prefs
++			// Backward compatibility: use UI prefs
+ 			IEclipsePreferences instance= access.getInstanceScope().getNode(CUIPlugin.PLUGIN_ID);
+ 			fDefaultFormatterId= instance.get(CCorePreferenceConstants.CODE_FORMATTER, null);
+ 			if (fDefaultFormatterId != null) {
+@@ -102,15 +101,8 @@ public class CustomCodeFormatterBlock ex
+ 			return;
+ 		}
+ 		fFormatterCombo.clearSelection();
+-		fFormatterCombo.setText(DEFAULT);
+-		Iterator<Map.Entry<String, String>> iterator = idMap.entrySet().iterator();
+-		while (iterator.hasNext()) {
+-			Map.Entry<String, String> entry = iterator.next();
+-			String val = entry.getValue();
+-			if (val != null && val.equals(fDefaultFormatterId)) {
+-				fFormatterCombo.setText(entry.getKey());
+-			}
+-		}
++		String formatter = getFormatterById(fDefaultFormatterId);
++		fFormatterCombo.setText(formatter);
+ 		handleFormatterChanged();
+ 	}
+ 
+@@ -132,16 +124,15 @@ public class CustomCodeFormatterBlock ex
+ 		if (fFormatterCombo == null) {
+ 			return fPrefs.get(CCorePreferenceConstants.CODE_FORMATTER, fDefaultFormatterId);
+ 		}
+-		String formatterId= idMap.get(fFormatterCombo.getText());
+-		return formatterId;
++		return idMap.get(fFormatterCombo.getText());
+ 	}
+ 
+ 	public Control createContents(Composite parent) {
+-		if (getNumberOfAvailableFormatters() == 0) {
+-			return parent;
++		if (idMap.size() == 1) {
++			return parent; // No selector is needed since there is only one formatter.
+ 		}
+ 		Composite composite = ControlFactory.createGroup(parent, FormatterMessages.CustomCodeFormatterBlock_formatter_name, 1);
+-		((GridData)composite.getLayoutData()).horizontalSpan = 5;
++		((GridData) composite.getLayoutData()).horizontalSpan = 5;
+ 
+ 		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICHelpContextIds.CODEFORMATTER_PREFERENCE_PAGE);
+ 
+@@ -154,9 +145,8 @@ public class CustomCodeFormatterBlock ex
+ 				handleFormatterChanged();
+ 			}
+ 		});
+-		Iterator<String> items = idMap.keySet().iterator();
+-		while (items.hasNext()) {
+-			fFormatterCombo.add(items.next());
++		for (String item : idMap.keySet()) {
++			fFormatterCombo.add(item);
+ 		}
+ 
+ 		final String noteTitle= FormatterMessages.CustomCodeFormatterBlock_formatter_note;
+@@ -175,27 +165,29 @@ public class CustomCodeFormatterBlock ex
+ 	}
+ 
+ 	private void initDefault() {
+-		boolean init = false;
++		if (fFormatterCombo == null) {
++			return;
++		}
+ 		String formatterID= fPrefs.get(CCorePreferenceConstants.CODE_FORMATTER, fDefaultFormatterId);
+-		if (formatterID != null) {
+-			Iterator<Map.Entry<String, String>> iterator = idMap.entrySet().iterator();
+-			while (iterator.hasNext()) {
+-				Map.Entry<String, String> entry = iterator.next();
++		fFormatterCombo.setText(getFormatterById(formatterID));
++	}
++
++	private String getFormatterById(String formatterId) {
++		String formatter = DEFAULT;
++		if (formatterId != null) {
++			for (Map.Entry<String, String> entry : idMap.entrySet()) {
+ 				String val = entry.getValue();
+-				if (val != null && val.equals(formatterID)) {
+-					fFormatterCombo.setText(entry.getKey());
+-					init = true;
++				if (formatterId.equals(val)) {
++					formatter = entry.getKey();
++					break;
+ 				}
+ 			}
+ 		}
+-		if (!init) {
+-			formatterID= null;
+-			fFormatterCombo.setText(DEFAULT);
+-		}
++		return formatter;
+ 	}
+ 
+ 	private void initializeFormatters() {
+ 		idMap = new HashMap<String, String>();
+ 		idMap.put(DEFAULT, CCorePreferenceConstants.DEFAULT_CODE_FORMATTER);
+ 		IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.FORMATTER_EXTPOINT_ID);
+ 		if (point != null) {
+@@ -210,8 +202,4 @@ public class CustomCodeFormatterBlock ex
+ 			}
+ 		}
+ 	}
+-	
+-	private final int getNumberOfAvailableFormatters() {
+-		return idMap.size() - 1;
+-	}
+ }
diff --git a/eclipse-cdt.spec b/eclipse-cdt.spec
index 749c825..bd76b4a 100644
--- a/eclipse-cdt.spec
+++ b/eclipse-cdt.spec
@@ -24,7 +24,7 @@ Epoch: 1
 Summary:        Eclipse C/C++ Development Tools (CDT) plugin
 Name:           eclipse-cdt
 Version:        %{majmin}.%{micro}
-Release:        1%{?dist}
+Release:        2%{?dist}
 License:        EPL and CPL
 Group:          Development/Tools
 URL:            http://www.eclipse.org/cdt
@@ -65,6 +65,9 @@ Patch7: %{name}-linuxtools-disable-jacoco.patch
 # Following fixes up CDT top-level pom
 Patch8: %{name}-disable-jacoco.patch
 
+# Following fixes bug #1138994
+Patch9: %{name}-custom-formatter.patch
+
 BuildRequires: tycho
 BuildRequires: tycho-extras
 BuildRequires: eclipse-pde >= 1:4.3.0
@@ -135,6 +138,7 @@ pushd %{cdt_snapshot}
 %patch4 -p1
 %patch6 -p1
 %patch8 -p1
+%patch9 -p1
 sed -i -e 's/<arch>x86<\/arch>/<arch>%{eclipse_arch}<\/arch>/g' pom.xml
 # Add secondary arch support if we are building there
 %ifarch %{arm} s390 s390x
@@ -361,6 +365,9 @@ rm -rf $installDir/eclipse/binary
 %doc %{cdt_snapshot}/releng/org.eclipse.cdt.releng/notice.html
 
 %changelog
+* Tue Sep 09 2014 Jeff Johnston <jjohnstn at redhat.com> 1:8.3.0-2
+- Fix rhbz#1138994 (NPE in Formatter preferences page)
+
 * Wed Mar 05 2014 Jeff Johnston <jjohnstn at redhat.com> 1:8.3.0-1
 - Update CDT to 8.3.0 (Kepler SR2)
 - Update Libhover to Linux Tools 2.2.1 (Kepler SR2)


More information about the scm-commits mailing list