aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2012-04-06 10:15:24 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-04-06 10:15:24 -0700
commite0f2a78624e5030c2b74f4207eb271cdcf0e4989 (patch)
tree34955dec3b30696a565f33d50cf3797e6244faf2
parent67d516c3411c02f5d1a90a663b1fcc78b8be25af (diff)
parentec90c4583e232c660d7441f6c775542da6896037 (diff)
downloadsdk-e0f2a78624e5030c2b74f4207eb271cdcf0e4989.zip
sdk-e0f2a78624e5030c2b74f4207eb271cdcf0e4989.tar.gz
sdk-e0f2a78624e5030c2b74f4207eb271cdcf0e4989.tar.bz2
am ec90c458: Merge "SDK: wrap NPE in getAttributeNS when editing XML files."
* commit 'ec90c4583e232c660d7441f6c775542da6896037': SDK: wrap NPE in getAttributeNS when editing XML files.
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java
index ea3f066..f8333bb 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java
@@ -27,6 +27,7 @@ import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDes
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeLabelProvider;
+import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
/** Label provider for the XML outlines and quick outlines: Use our own icons,
@@ -52,18 +53,18 @@ class OutlineLabelProvider extends JFaceNodeLabelProvider {
String text = super.getText(element);
if (element instanceof Element) {
Element e = (Element) element;
- String id = e.getAttributeNS(ANDROID_URI, ATTR_ID);
+ String id = getAttributeNS(e, ANDROID_URI, ATTR_ID);
if (id == null || id.length() == 0) {
- id = e.getAttributeNS(ANDROID_URI, ATTR_NAME);
+ id = getAttributeNS(e, ANDROID_URI, ATTR_NAME);
if (id == null || id.length() == 0) {
id = e.getAttribute(ATTR_NAME);
if (id == null || id.length() == 0) {
- id = e.getAttributeNS(ANDROID_URI, ATTR_TEXT);
+ id = getAttributeNS(e, ANDROID_URI, ATTR_TEXT);
if (id != null && id.length() > 15) {
id = id.substring(0, 12) + "...";
}
if (id == null || id.length() == 0) {
- id = e.getAttributeNS(ANDROID_URI, ATTR_SRC);
+ id = getAttributeNS(e, ANDROID_URI, ATTR_SRC);
if (id != null && id.length() > 0) {
if (id.startsWith(DRAWABLE_PREFIX)) {
id = id.substring(DRAWABLE_PREFIX.length());
@@ -87,4 +88,20 @@ class OutlineLabelProvider extends JFaceNodeLabelProvider {
}
return text;
}
-} \ No newline at end of file
+
+ /**
+ * Wrapper around {@link Element#getAttributeNS(String, String)}.
+ * <p/>
+ * The implementation used in Eclipse's XML editor sometimes internally throws
+ * an NPE instead of politely returning null.
+ *
+ * @see Element#getAttributeNS(String, String)
+ */
+ private String getAttributeNS(Element e, String uri, String name) throws DOMException {
+ try {
+ return e.getAttributeNS(uri, name);
+ } catch (NullPointerException ignore) {
+ return null;
+ }
+ }
+}