1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-15 20:25:46 +02:00

Bug #220838 : null pointer exception in HoldsOption.java when converting tools

This commit is contained in:
Oleg Krasilnikov 2008-03-03 10:46:12 +00:00
parent 629404da42
commit 6a00c11154

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2007 Symbian Ltd and others. * Copyright (c) 2005, 2008 Symbian Ltd and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -30,6 +30,9 @@ import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo; import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/** /**
* Implements the functionality that is needed to hold options and option * Implements the functionality that is needed to hold options and option
@ -58,11 +61,11 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
// Members that must have the same values on creation as the derived class // Members that must have the same values on creation as the derived class
private boolean resolved; private boolean resolved;
// Parent and children // Parent and children
private Vector categoryIds; private Vector<String> categoryIds;
private Map categoryMap; private Map<String, IOptionCategory> categoryMap;
private List childOptionCategories; private List<IOptionCategory> childOptionCategories;
private Vector optionList; private Vector<Option> optionList;
private Map optionMap; private Map<String, Option> optionMap;
// Miscellaneous // Miscellaneous
private boolean isDirty = false; private boolean isDirty = false;
private boolean rebuildState; private boolean rebuildState;
@ -71,6 +74,7 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
* C O N S T R U C T O R S * C O N S T R U C T O R S
*/ */
@SuppressWarnings("unused")
private HoldsOptions() { private HoldsOptions() {
// prevent accidental construction of class without setting up // prevent accidental construction of class without setting up
// resolved // resolved
@ -94,9 +98,9 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
boolean copyIds = id.equals(source.id); boolean copyIds = id.equals(source.id);
if (source.optionList != null) { if (source.optionList != null) {
Iterator iter = source.getOptionList().listIterator(); Iterator<Option> iter = source.getOptionList().listIterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Option option = (Option) iter.next(); Option option = iter.next();
int nnn = ManagedBuildManager.getRandomNumber(); int nnn = ManagedBuildManager.getRandomNumber();
String subId; String subId;
String subName; String subName;
@ -194,7 +198,7 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
*/ */
protected void serialize(ICStorageElement element) throws BuildException { protected void serialize(ICStorageElement element) throws BuildException {
Iterator iter; Iterator<IOptionCategory> iter;
if (childOptionCategories != null) { if (childOptionCategories != null) {
iter = childOptionCategories.listIterator(); iter = childOptionCategories.listIterator();
@ -205,10 +209,10 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
} }
} }
List optionElements = getOptionList(); List<Option> optionElements = getOptionList();
iter = optionElements.listIterator(); Iterator<Option> iter2 = optionElements.listIterator();
while (iter.hasNext()) { while (iter2.hasNext()) {
Option option = (Option) iter.next(); Option option = iter2.next();
ICStorageElement optionElement = element.createChild(OPTION); ICStorageElement optionElement = element.createChild(OPTION);
option.serialize(optionElement); option.serialize(optionElement);
} }
@ -235,7 +239,7 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
* @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#createOptions(IHoldsOptions) * @see org.eclipse.cdt.managedbuilder.core.IHoldsOptions#createOptions(IHoldsOptions)
*/ */
public void createOptions(IHoldsOptions superClass) { public void createOptions(IHoldsOptions superClass) {
Iterator iter = ((HoldsOptions)superClass).getOptionList().listIterator(); Iterator<Option> iter = ((HoldsOptions)superClass).getOptionList().listIterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Option optionChild = (Option) iter.next(); Option optionChild = (Option) iter.next();
int nnn = ManagedBuildManager.getRandomNumber(); int nnn = ManagedBuildManager.getRandomNumber();
@ -272,7 +276,7 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
options = superClass.getOptions(); options = superClass.getOptions();
} }
// Our options take precedence. // Our options take precedence.
Vector ourOpts = getOptionList(); Vector<Option> ourOpts = getOptionList();
if (options != null) { if (options != null) {
for (int i = 0; i < ourOpts.size(); i++) { for (int i = 0; i < ourOpts.size(); i++) {
int j = options.length; int j = options.length;
@ -410,9 +414,9 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
/* (non-Javadoc) /* (non-Javadoc)
* Memory-safe way to access the vector of category IDs * Memory-safe way to access the vector of category IDs
*/ */
private Vector getCategoryIds() { private Vector<String> getCategoryIds() {
if (categoryIds == null) { if (categoryIds == null) {
categoryIds = new Vector(); categoryIds = new Vector<String>();
} }
return categoryIds; return categoryIds;
} }
@ -422,7 +426,7 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
*/ */
public void addChildCategory(IOptionCategory category) { public void addChildCategory(IOptionCategory category) {
if (childOptionCategories == null) if (childOptionCategories == null)
childOptionCategories = new ArrayList(); childOptionCategories = new ArrayList<IOptionCategory>();
childOptionCategories.add(category); childOptionCategories.add(category);
} }
@ -436,9 +440,9 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
/* (non-Javadoc) /* (non-Javadoc)
* Memeory-safe way to access the map of category IDs to categories * Memeory-safe way to access the map of category IDs to categories
*/ */
private Map getCategoryMap() { private Map<String, IOptionCategory> getCategoryMap() {
if (categoryMap == null) { if (categoryMap == null) {
categoryMap = new HashMap(); categoryMap = new HashMap<String, IOptionCategory>();
} }
return categoryMap; return categoryMap;
} }
@ -446,9 +450,9 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
/* (non-Javadoc) /* (non-Javadoc)
* Memory-safe way to access the list of options * Memory-safe way to access the list of options
*/ */
private Vector getOptionList() { private Vector<Option> getOptionList() {
if (optionList == null) { if (optionList == null) {
optionList = new Vector(); optionList = new Vector<Option>();
} }
return optionList; return optionList;
} }
@ -456,9 +460,9 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
/* (non-Javadoc) /* (non-Javadoc)
* Memory-safe way to access the list of IDs to options * Memory-safe way to access the list of IDs to options
*/ */
private Map getOptionMap() { private Map<String, Option> getOptionMap() {
if (optionMap == null) { if (optionMap == null) {
optionMap = new HashMap(); optionMap = new HashMap<String, Option>();
} }
return optionMap; return optionMap;
} }
@ -495,15 +499,12 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
*/ */
protected boolean isDirty() { protected boolean isDirty() {
// If I need saving, just say yes // If I need saving, just say yes
if (isDirty) return true; if (isDirty)
return true;
// Otherwise see if any options need saving for (Option option : getOptionList())
List optionElements = getOptionList(); if (option.isDirty())
Iterator iter = optionElements.listIterator(); return true;
while (iter.hasNext()) {
Option option = (Option) iter.next();
if (option.isDirty()) return true;
}
return isDirty; return isDirty;
} }
@ -516,15 +517,11 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
this.isDirty = isDirty; this.isDirty = isDirty;
// Propagate "false" to the children // Propagate "false" to the children
if (!isDirty) { if (!isDirty) {
List optionElements = getOptionList(); for (Option option : getOptionList())
Iterator iter = optionElements.listIterator();
while (iter.hasNext()) {
Option option = (Option) iter.next();
if(!option.isExtensionElement()) if(!option.isExtensionElement())
option.setDirty(false); option.setDirty(false);
} }
} }
}
/* (non-Javadoc) /* (non-Javadoc)
* Resolve the element IDs to interface references. Intended to be * Resolve the element IDs to interface references. Intended to be
@ -534,15 +531,11 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
if (!resolved) { if (!resolved) {
resolved = true; resolved = true;
// Call resolveReferences on our children // Call resolveReferences on our children
Iterator optionIter = getOptionList().iterator(); for (Option current : getOptionList()) {
while (optionIter.hasNext()) {
Option current = (Option)optionIter.next();
current.resolveReferences(); current.resolveReferences();
} }
// Somewhat wasteful, but use the vector to retrieve the categories in proper order // Somewhat wasteful, but use the vector to retrieve the categories in proper order
Iterator catIter = getCategoryIds().iterator(); for (String id : getCategoryIds()) {
while (catIter.hasNext()) {
String id = (String)catIter.next();
IOptionCategory current = (IOptionCategory)getCategoryMap().get(id); IOptionCategory current = (IOptionCategory)getCategoryMap().get(id);
if (current instanceof Tool) { if (current instanceof Tool) {
((Tool)current).resolveReferences(); ((Tool)current).resolveReferences();
@ -560,8 +553,30 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
*/ */
public IOption getOptionToSet(IOption option, boolean adjustExtension) throws BuildException{ public IOption getOptionToSet(IOption option, boolean adjustExtension) throws BuildException{
IOption setOption = null; IOption setOption = null;
if(option.getOptionHolder() != this) // start changes
option = getOptionBySuperClassId(option.getId()); if(option.getOptionHolder() != this) {
// option = getOptionBySuperClassId(option.getId());
IOption op = getOptionBySuperClassId(option.getId());
if (op == null && option.getSuperClass() != null) {
op = getOptionBySuperClassId(option.getSuperClass().getId());
if (op == null) {
ManagedBuilderCorePlugin.log(
new Status(
IStatus.ERROR,
ManagedBuilderCorePlugin.getUniqueIdentifier(),
IStatus.OK,
"Cannot get OptionToSet for option " +
option.getId() + " @ holder " +
option.getOptionHolder().getId() + "\nI'm holder " +
getId(),
null)
);
} else
option = op;
} else
option = op;
}
// end changes
if(adjustExtension){ if(adjustExtension){
for(; option != null && !option.isExtensionElement(); option=option.getSuperClass()){} for(; option != null && !option.isExtensionElement(); option=option.getSuperClass()){}
@ -623,12 +638,9 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
return true; return true;
// Otherwise see if any options need saving // Otherwise see if any options need saving
List optionElements = getOptionList(); for (Option option : getOptionList())
Iterator iter = optionElements.listIterator(); if (option.needsRebuild())
while (iter.hasNext()) { return true;
Option option = (Option) iter.next();
if (option.needsRebuild()) return true;
}
return rebuildState; return rebuildState;
} }
@ -640,16 +652,11 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
rebuildState = rebuild; rebuildState = rebuild;
// Propagate "false" to the children // Propagate "false" to the children
if (!rebuildState) { if (!rebuildState)
List optionElements = getOptionList(); for (Option option : getOptionList())
Iterator iter = optionElements.listIterator();
while (iter.hasNext()) {
Option option = (Option) iter.next();
if(!option.isExtensionElement()) if(!option.isExtensionElement())
option.setRebuildState(false); option.setRebuildState(false);
} }
}
}
public void propertiesChanged() { public void propertiesChanged() {
if(isExtensionElement()) if(isExtensionElement())
@ -710,33 +717,24 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
protected abstract IResourceInfo getParentResourceInfo(); protected abstract IResourceInfo getParentResourceInfo();
public String[] getRequiredTypeIds() { public String[] getRequiredTypeIds() {
List list = new ArrayList(); List<String> list = new ArrayList<String>();
IOption options[] = getOptions(); for(IOption op : getOptions())
for(int i = 0; i < options.length; i++){ list.addAll(Arrays.asList(((Option)op).getRequiredTypeIds()));
Option option = (Option)options[i]; return list.toArray(new String[list.size()]);
list.addAll(Arrays.asList(option.getRequiredTypeIds()));
}
return (String[])list.toArray(new String[list.size()]);
} }
public String[] getSupportedTypeIds() { public String[] getSupportedTypeIds() {
List list = new ArrayList(); List<String> list = new ArrayList<String>();
IOption options[] = getOptions(); for(IOption op : getOptions())
for(int i = 0; i < options.length; i++){ list.addAll(Arrays.asList(((Option)op).getSupportedTypeIds()));
Option option = (Option)options[i]; return list.toArray(new String[list.size()]);
list.addAll(Arrays.asList(option.getSupportedTypeIds()));
}
return (String[])list.toArray(new String[list.size()]);
} }
public String[] getSupportedValueIds(String typeId) { public String[] getSupportedValueIds(String typeId) {
List list = new ArrayList(); List<String> list = new ArrayList<String>();
IOption options[] = getOptions(); for(IOption op : getOptions())
for(int i = 0; i < options.length; i++){ list.addAll(Arrays.asList(((Option)op).getSupportedValueIds(typeId)));
Option option = (Option)options[i]; return list.toArray(new String[list.size()]);
list.addAll(Arrays.asList(option.getSupportedValueIds(typeId)));
}
return (String[])list.toArray(new String[list.size()]);
} }
public boolean requiresType(String typeId) { public boolean requiresType(String typeId) {
@ -757,13 +755,10 @@ public abstract class HoldsOptions extends BuildObject implements IHoldsOptions,
return true; return true;
if(optionList != null && optionList.size() != 0){ if(optionList != null && optionList.size() != 0){
Option option; for(Option option : optionList)
for(Iterator iter = optionList.iterator(); iter.hasNext();){
option = (Option)iter.next();
if(option.hasCustomSettings()) if(option.hasCustomSettings())
return true; return true;
} }
}
return false; return false;
} }