Skip to content

Commit

Permalink
TEIIDDES-1518: Fixes for thrown exceptions
Browse files Browse the repository at this point in the history
* TeiidResourceNode
 * Incorrect logic in hasChildren. Possible for dirty flag to be false and
   childen to be null

* TeiidResourceAdapterFactory
 * Safety check that children is not null

* DisplayNode
* DisplayNodeUtils
* ReconcilerPanel
* TransformationSqlHelper
* BuilderUtils
* LanguageObjectContentProvider
* SqlTransformationMappingRootValidationRule
* WebServiceUtil
 * Checks used to do use instanceof which covered the possibility that
   object is null so explicit null check needs to be included to avoid
   expections

* QueryImpl
 * Copy n paste error
  • Loading branch information
Paul Richardson committed Dec 13, 2012
1 parent 369e925 commit d14d195
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ public ITeiidServer getTeiidServer() {

@Override
public boolean hasChildren() {
return !dirty || (children != null && ! children.isEmpty());
if (dirty)
return false;

return children != null && ! children.isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ private ITeiidServer adaptToTeiidServer(ITeiidResourceNode teiidResourceNode) {
private TeiidServerContainerNode adaptToTeiidServerContainerNode(ITeiidResourceNode teiidResourceNode) {
if (teiidResourceNode.hasChildren()) {
List<? extends ITeiidContentNode<?>> children = teiidResourceNode.getChildren();
if (children == null)
return null;

ITeiidContentNode<?> child = children.get(0);
if (child instanceof TeiidServerContainerNode)
return (TeiidServerContainerNode) child;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static ILanguageObject getBuilderLanguageObject( ILanguageObject theLangO

ILanguageObject result = theLangObj;

if ((theLangObj.isFunction()) && ((IFunction)theLangObj).isImplicit()) {
if (theLangObj != null && theLangObj.isFunction() && ((IFunction)theLangObj).isImplicit()) {
// according to Alex, all implicit functions are conversions and
// the first argument is what is being converted
result = getBuilderLanguageObject(((IFunction)theLangObj).getArgs()[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Iterator;
import java.util.List;
import org.teiid.designer.query.sql.lang.ICriteria;
import org.teiid.designer.query.sql.lang.IExpression;
import org.teiid.designer.query.sql.lang.ILanguageObject;

/**
Expand Down Expand Up @@ -175,7 +174,7 @@ public boolean isInExpression() {
public DisplayNode getExpression() {
DisplayNode parentNode = this;
while (parentNode != null) {
if (parentNode.languageObject.isExpression()) {
if (parentNode.languageObject != null && parentNode.languageObject.isExpression()) {
return parentNode;
}
parentNode = parentNode.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.teiid.designer.query.sql.lang.ICompareCriteria;
import org.teiid.designer.query.sql.lang.ICompoundCriteria;
import org.teiid.designer.query.sql.lang.ICriteria;
import org.teiid.designer.query.sql.lang.IExpression;
import org.teiid.designer.query.sql.lang.IFrom;
import org.teiid.designer.query.sql.lang.IGroupBy;
import org.teiid.designer.query.sql.lang.IIsNullCriteria;
Expand Down Expand Up @@ -205,7 +204,7 @@ public static boolean hasSymbol( DisplayNode node ) {
* @return true if the node has at least one expression, false if not.
*/
public static boolean hasExpression( DisplayNode node ) {
if (node.languageObject.isExpression()) {
if (node.languageObject != null && node.languageObject.isExpression()) {
return true;
}
List nodes = node.getDisplayNodeList();
Expand Down Expand Up @@ -289,7 +288,7 @@ public static int getEndIndexOfPreviousSymbol( DisplayNode node,
*/
public static int getStartIndexOfNextExpression( DisplayNode node,
int index ) {
if (node.languageObject.isExpression()) {
if (node.languageObject != null && node.languageObject.isExpression()) {
if (node.isAnywhereWithin(index)) {
return node.getStartIndex();
}
Expand Down Expand Up @@ -319,7 +318,7 @@ public static int getStartIndexOfNextExpression( DisplayNode node,
public static int getEndIndexOfPreviousExpression( DisplayNode node,
int index ) {
int prevEnd = -1;
if (node.languageObject.isExpression()) {
if (node.languageObject != null && node.languageObject.isExpression()) {
if (node.isAnywhereWithin(index)) {
return node.getEndIndex() + 1;
}
Expand Down Expand Up @@ -889,7 +888,7 @@ public static DisplayNode getExpressionForNode( DisplayNode node ) {
return node.getExpression();
}
return null;
} else if (node.languageObject.isExpression() && !(node.languageObject instanceof IScalarSubquery)) {
} else if (node.languageObject != null && node.languageObject.isExpression() && !(node.languageObject instanceof IScalarSubquery)) {
return node;
} else if (node.isInExpression()) {
return node.getExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private Object[] getChildren( ICriteria theCriteria ) {
private Object[] getChildren( IExpression theExpression ) {
Object[] result = null;

if (theExpression.isFunction()) {
if (theExpression != null && theExpression.isFunction()) {
result = getChildren((IFunction)theExpression);
}

Expand All @@ -128,7 +128,7 @@ private Object[] getChildren( IFunction theFunction ) {
// according to Alex, all implicit functions are conversions and
// the first argument is what is being converted (which could be a function or expression)
IExpression arg = theFunction.getArgs()[0];
result = (arg.isFunction()) ? getChildren((IFunction)arg) : getChildren(arg);
result = (arg != null && arg.isFunction()) ? getChildren((IFunction)arg) : getChildren(arg);
} else {
IExpression[] args = theFunction.getArgs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ void expressionButtonPressed() {

// Need to crate an Expression Symbol (constant = NULL) name = "expr"
List symbolsList = new ArrayList(1);
if (langObj.isExpression()) {
if (langObj != null && langObj.isExpression()) {
IQueryService queryService = ModelerCore.getTeiidQueryService();
IQueryFactory factory = queryService.createQueryFactory();
IExpressionSymbol newExpression = factory.createExpressionSymbol(EXPRESSION, (IExpression)langObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ private void validateQuery( final IQuery query,
IExpression rightExpression = compare.getRightExpression();
// in case of CAST/CONVERT functions get the elementsymbol in the function
// and compare types
if (leftExpression.isFunction()) {
if (leftExpression != null && leftExpression.isFunction()) {
IFunction leftFunction = (IFunction)leftExpression;
String descriptorName = leftFunction.getFunctionDescriptor().getName();
if (leftFunction.isImplicit()
Expand All @@ -884,7 +884,7 @@ private void validateQuery( final IQuery query,
leftExpression = leftFunction.getArg(0);
}
}
if (rightExpression.isFunction()) {
if (rightExpression != null && rightExpression.isFunction()) {
IFunction rightFunction = (IFunction)rightExpression;
String descriptorName = rightFunction.getFunctionDescriptor().getName();
if (rightFunction.isImplicit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ public static String getSingleElementSymbolShortName( IExpression symbol,
// get the IExpression
IExpression expr = ((IExpressionSymbol)symbol).getExpression();
// IExpression is a Function, look for implicit function
if (expr.isFunction()) {
if (expr != null && expr.isFunction()) {
// if implicit function, use the arg symbol name, otherwise use function name
IFunction func = (IFunction)expr;
if (func.isImplicit()) {
Expand Down Expand Up @@ -1719,7 +1719,7 @@ private static int concatSymbolLength( IExpression exprObject ) {
IElementSymbol elSymbol = null;
int stringLength = 0;

if (exprObject.isFunction()) {
if (exprObject != null && exprObject.isFunction()) {
IFunction myFunc = (IFunction)exprObject;
if (isDecodeOrSubString(myFunc)) {
return stringLength += getMaxStringLength(myFunc);
Expand All @@ -1731,7 +1731,7 @@ private static int concatSymbolLength( IExpression exprObject ) {
for (int i = 0; i < args.length; i++) {
IExpression symbol = args[i];

if (symbol.isFunction()) {
if (symbol != null && symbol.isFunction()) {
stringLength += concatSymbolLength(symbol);
}

Expand Down Expand Up @@ -1799,7 +1799,7 @@ public static int getSymbolLength( IExpression symbol ) {
for (int i = 0; i < args.length; i++) {
IExpression exprSymbol = args[i];

if (exprSymbol.isFunction()) {
if (exprSymbol != null && exprSymbol.isFunction()) {
stringLength += concatSymbolLength(exprSymbol);
}
if (exprSymbol instanceof IElementSymbol) {
Expand Down Expand Up @@ -1933,7 +1933,7 @@ public static Map getRenamedSymbolsMap( List<IExpression> symbols ) {
}
}
}
} else if (sSymbol.isExpression()) {
} else if (sSymbol != null && sSymbol.isExpression()) {
seSymbols.add(sSymbol);
}
}
Expand Down Expand Up @@ -2445,7 +2445,7 @@ public static List renameConflictingSymbols( List seSymbols ) {
// ----------------------------------------------------------------
// Current Symbol is SingleElementSymbol - rename it if necessary
// ----------------------------------------------------------------
} else if (currentSelectSymbol.isExpression()) {
} else if (currentSelectSymbol != null && currentSelectSymbol.isExpression()) {
IExpression renamedSymbol = renameSymbolUsingMap((IExpression)currentSelectSymbol,
workingRenSymMap);
newSymbols.add(renamedSymbol);
Expand Down Expand Up @@ -3118,7 +3118,7 @@ public static IFunction getConversion( String originalTypeName,

public static boolean isConvertFunction( IExpressionSymbol exprSymbol ) {
IExpression expr = exprSymbol.getExpression();
if (expr.isFunction()) {
if (expr != null && expr.isFunction()) {
String fName = ((IFunction)expr).getName();
if (fName.equalsIgnoreCase(ISQLConstants.CONVERT)) {
return true;
Expand Down Expand Up @@ -3150,7 +3150,7 @@ public static IExpressionSymbol convertExpressionSymbol( IExpressionSymbol symbo
// Handle case where the IExpression is already a Convert Function
if (isConvertFunction(symbol)) {
IExpression cExpr = getConvertedExpr(symbol);
if (cExpr.isExpression()) {
if (cExpr != null && cExpr.isExpression()) {
IExpression seSymbol = (IExpression)cExpr;

IDataTypeManagerService service = ModelerCore.getTeiidDataTypeManagerService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static String getXpath(IAssignmentStatement statement) {
public static IFunction getXpathFunction(IAssignmentStatement statement) {
if (statement.getExpression() != null) {
IExpression expr = statement.getExpression();
if (expr.isFunction()) {
if (expr != null && expr.isFunction()) {
IFunction function = (IFunction)expr;
if (XPATHVALUE.equalsIgnoreCase(function.getName())) {
return function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void setSelect(ISelect select) {

@Override
public IFrom getFrom() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getFrom());
}

@Override
Expand All @@ -92,7 +92,7 @@ public void setFrom(IFrom from) {

@Override
public IInto getInto() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getInto());
}

@Override
Expand All @@ -114,7 +114,7 @@ public void setCriteria(ICriteria where) {

@Override
public ICriteria getHaving() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getHaving());
}

@Override
Expand All @@ -125,7 +125,7 @@ public void setHaving(ICompareCriteria having) {

@Override
public IGroupBy getGroupBy() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getGroupBy());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void setSelect(ISelect select) {

@Override
public IFrom getFrom() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getFrom());
}

@Override
Expand All @@ -92,7 +92,7 @@ public void setFrom(IFrom from) {

@Override
public IInto getInto() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getInto());
}

@Override
Expand All @@ -114,7 +114,7 @@ public void setCriteria(ICriteria where) {

@Override
public ICriteria getHaving() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getHaving());
}

@Override
Expand All @@ -125,7 +125,7 @@ public void setHaving(ICompareCriteria having) {

@Override
public IGroupBy getGroupBy() {
return getFactory().convert(getDelegate().getSelect());
return getFactory().convert(getDelegate().getGroupBy());
}

@Override
Expand Down

0 comments on commit d14d195

Please sign in to comment.