From f47baf1439853c55aef67fd93fe2dc132df0af50 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Thu, 31 May 2012 12:37:15 -0700 Subject: Eclipse 4.x fix: Don't attempt to get display too early Also fix a couple of potential NPEs. Change-Id: I80d6b625d672ad2e7b96f2fce311aa4347a45a33 --- .../src/com/android/ide/eclipse/adt/AdtPlugin.java | 35 +++++++++++++--------- .../editors/layout/properties/XmlProperty.java | 6 ++++ .../eclipse/adt/internal/welcome/AdtStartup.java | 2 ++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java index 10cd093..48cebee 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java @@ -211,8 +211,6 @@ public class AdtPlugin extends AbstractUIPlugin implements ILogger, ISdkLog { public void start(BundleContext context) throws Exception { super.start(context); - Display display = getDisplay(); - // set the default android console. mAndroidConsole = new MessageConsole("Android", null); //$NON-NLS-1$ ConsolePlugin.getDefault().getConsoleManager().addConsoles( @@ -221,17 +219,6 @@ public class AdtPlugin extends AbstractUIPlugin implements ILogger, ISdkLog { // get the stream to write in the android console. mAndroidConsoleStream = mAndroidConsole.newMessageStream(); mAndroidConsoleErrorStream = mAndroidConsole.newMessageStream(); - mRed = new Color(display, 0xFF, 0x00, 0x00); - - // because this can be run, in some cases, by a non ui thread, and because - // changing the console properties update the ui, we need to make this change - // in the ui thread. - display.asyncExec(new Runnable() { - @Override - public void run() { - mAndroidConsoleErrorStream.setColor(mRed); - } - }); // get the eclipse store IPreferenceStore eclipseStore = getPreferenceStore(); @@ -303,12 +290,32 @@ public class AdtPlugin extends AbstractUIPlugin implements ILogger, ISdkLog { DesignerPlugin.dispose(); - mRed.dispose(); + if (mRed != null) { + mRed.dispose(); + mRed = null; + } + synchronized (AdtPlugin.class) { sPlugin = null; } } + /** Called when the workbench has been started */ + public void workbenchStarted() { + Display display = getDisplay(); + mRed = new Color(display, 0xFF, 0x00, 0x00); + + // because this can be run, in some cases, by a non ui thread, and because + // changing the console properties update the ui, we need to make this change + // in the ui thread. + display.asyncExec(new Runnable() { + @Override + public void run() { + mAndroidConsoleErrorStream.setColor(mRed); + } + }); + } + /** * Returns the shared instance * diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java index c846ea1..6591575 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java @@ -167,6 +167,9 @@ class XmlProperty extends Property { Object s = null; try { Element element = (Element) mNode.getXmlNode(); + if (element == null) { + return false; + } String name = mDescriptor.getXmlLocalName(); String uri = mDescriptor.getNamespaceUri(); if (uri != null) { @@ -182,6 +185,9 @@ class XmlProperty extends Property { public String getStringValue() { Element element = (Element) mNode.getXmlNode(); + if (element == null) { + return null; + } String name = mDescriptor.getXmlLocalName(); String uri = mDescriptor.getNamespaceUri(); Attr attr; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/welcome/AdtStartup.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/welcome/AdtStartup.java index f6dc870..0fcf102 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/welcome/AdtStartup.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/welcome/AdtStartup.java @@ -68,6 +68,8 @@ public class AdtStartup implements IStartup { } initializeWindowCoordinator(); + + AdtPlugin.getDefault().workbenchStarted(); } private boolean isFirstTime() { -- cgit v1.1