diff options
author | Raphael <raphael@google.com> | 2009-09-04 17:14:37 -0700 |
---|---|---|
committer | Raphael <raphael@google.com> | 2009-09-04 17:14:37 -0700 |
commit | 714d126c89e40570dfef3ec8f2565ec81d563248 (patch) | |
tree | 26d744fe4de82abe5f40bc6dd1fab975fb532f36 /eclipse | |
parent | 816c14d9bdb50bb2b8d4bc1e970858955cbbbfda (diff) | |
download | sdk-714d126c89e40570dfef3ec8f2565ec81d563248.zip sdk-714d126c89e40570dfef3ec8f2565ec81d563248.tar.gz sdk-714d126c89e40570dfef3ec8f2565ec81d563248.tar.bz2 |
ADT: fix an NPE that can happen when an XML file resource is being
refreshed by Eclipse whilst the SDK is not finished loading.
Change-Id: I970255925d98f7b84a726fa37bf1fef3d25ab520
Diffstat (limited to 'eclipse')
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/XmlEditor.java | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/XmlEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/XmlEditor.java index 0129048..aca6c8f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/XmlEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/XmlEditor.java @@ -37,7 +37,7 @@ import org.eclipse.ui.part.FileEditorInput; import org.w3c.dom.Document; /** - * Multi-page form editor for /res/xml XML files. + * Multi-page form editor for /res/xml XML files. */ public class XmlEditor extends AndroidEditor { @@ -69,7 +69,7 @@ public class XmlEditor extends AndroidEditor { * <p/> * The {@link XmlEditor} can handle XML files that have a <searchable> or * <Preferences> root XML element with the adequate xmlns:android attribute. - * + * * @return True if the {@link XmlEditor} can handle that file. */ public static boolean canHandleFile(IFile file) { @@ -77,14 +77,17 @@ public class XmlEditor extends AndroidEditor { IProject project = file.getProject(); IAndroidTarget target = Sdk.getCurrent().getTarget(project); if (target != null) { + // Note: the target data can be null when an SDK is not finished loading yet. + // We can potentially arrive here when Eclipse is started with a file previously + // open and the resource gets refreshed -- at that point we may not have the SDK yet. AndroidTargetData data = Sdk.getCurrent().getTargetData(target); - + FirstElementParser.Result result = FirstElementParser.parse( file.getLocation().toOSString(), SdkConstants.NS_RESOURCES); - - if (result != null) { - String name = result.getElement(); + + if (result != null && data != null) { + String name = result.getElement(); if (name != null && result.getXmlnsPrefix() != null) { DocumentDescriptor desc = data.getXmlDescriptors().getDescriptor(); for (ElementDescriptor elem : desc.getChildren()) { @@ -96,7 +99,7 @@ public class XmlEditor extends AndroidEditor { } } } - + return false; } @@ -106,7 +109,7 @@ public class XmlEditor extends AndroidEditor { * Returns whether the "save as" operation is supported by this editor. * <p/> * Save-As is a valid operation for the ManifestEditor since it acts on a - * single source file. + * single source file. * * @see IEditorPart */ @@ -125,7 +128,7 @@ public class XmlEditor extends AndroidEditor { } catch (PartInitException e) { AdtPlugin.log(e, "Error creating nested page"); //$NON-NLS-1$ } - + } /* (non-java doc) @@ -140,10 +143,10 @@ public class XmlEditor extends AndroidEditor { setPartName(String.format("%1$s", file.getName())); } } - + /** * Processes the new XML Model, which XML root node is given. - * + * * @param xml_doc The XML document, if available, or null if none exists. */ @Override @@ -152,10 +155,10 @@ public class XmlEditor extends AndroidEditor { initUiRootNode(false /*force*/); mUiRootNode.loadFromXmlNode(xml_doc); - + super.xmlModelChanged(xml_doc); } - + /** * Creates the initial UI Root Node, including the known mandatory elements. * @param force if true, a new UiRootNode is recreated even if it already exists. @@ -198,5 +201,5 @@ public class XmlEditor extends AndroidEditor { mUiRootNode.reloadFromXmlNode(mUiRootNode.getXmlNode()); } } - + } |