Skip to content

Commit

Permalink
[276] NPE on BinaryExpression/UnaryExpression with null expression (#277
Browse files Browse the repository at this point in the history
)

* [276] NPE on BinaryExpression/UnaryExpression with null expression


---------

Co-authored-by: Thomas Guiu <[email protected]>
  • Loading branch information
tguiu and Thomas Guiu authored Nov 27, 2024
1 parent 8ecb100 commit 529bfb3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,67 +338,58 @@ public static String getValueOfDataValue(DataValue dataValue_p) {
return getValueOfDataValue(dataValue_p, false);
}

private static String normalize(String value, String _default) {
if (value == null) {
return _default;
}
return value;
}

private static String getValueOfDataValue(DataValue dataValue_p, boolean simple) {
// Test the type of the Data Value
if (dataValue_p instanceof LiteralNumericValue)
{
String value = ((LiteralNumericValue) dataValue_p).getValue();
if (value == null) {
return normalize( ((LiteralNumericValue) dataValue_p).getValue(), CapellaServices.UNDEFINED_CHEVRON);
}
if (dataValue_p instanceof BinaryExpression)
{
return normalize((((BinaryExpression) dataValue_p).getExpression()), CapellaServices.NULL_LOWER_CASE);
}
if (dataValue_p instanceof UnaryExpression)
{
return normalize( (((UnaryExpression) dataValue_p).getExpression()), CapellaServices.NULL_LOWER_CASE);
}
if (dataValue_p instanceof LiteralBooleanValue)
{
return (String.valueOf(((LiteralBooleanValue) dataValue_p).isValue()));
}
if (dataValue_p instanceof LiteralStringValue)
{
String value = ((LiteralStringValue) dataValue_p).getValue();
if (null == value)
{
return CapellaServices.UNDEFINED_CHEVRON;
}
else {
return value;
if (value.trim().isEmpty())
{
value = "\"" + value + "\"";
}
}
else
return (value);
}
if (dataValue_p instanceof CollectionValue)
{
if (dataValue_p instanceof BinaryExpression)
CollectionValue collectionValue = (CollectionValue) dataValue_p;
String collectionName = collectionValue.getName();
if (collectionName == null || (collectionName!= null && collectionName.isEmpty()))
{
return (((BinaryExpression) dataValue_p).getExpression());
}
else
if (dataValue_p instanceof UnaryExpression)
{
return (((UnaryExpression) dataValue_p).getExpression());
}
else
if (dataValue_p instanceof LiteralBooleanValue)
{
return (String.valueOf(((LiteralBooleanValue) dataValue_p).isValue()));
}
else
if (dataValue_p instanceof LiteralStringValue)
{
String value = ((LiteralStringValue) dataValue_p).getValue();
if (null == value)
{
value = CapellaServices.UNDEFINED_CHEVRON;
}
else
{
if (value.trim().isEmpty())
{
value = "\"" + value + "\"";
}
}
return (value);
}
else
if (dataValue_p instanceof CollectionValue)
{
CollectionValue collectionValue = (CollectionValue) dataValue_p;
String collectionName = collectionValue.getName();
if (collectionName == null || (collectionName!= null && collectionName.isEmpty()))
{
collectionName += CapellaServices.NO_NAME;
}
Type type = collectionValue.getType();
if (type != null)
{
collectionName += " : " + CapellaServices.getFullDataPkgHierarchyLink(type);
}
return collectionName;
}
collectionName += CapellaServices.NO_NAME;
}
Type type = collectionValue.getType();
if (type != null)
{
collectionName += " : " + CapellaServices.getFullDataPkgHierarchyLink(type);
}
return collectionName;
}

EObject referencedValue = getReferencedValue(dataValue_p);
Expand All @@ -414,8 +405,7 @@ private static String getValueOfDataValue(DataValue dataValue_p, boolean simple)

return CapellaServices.getHyperlinkFromElement(referencedValue);
}
else
return CapellaServices.getFullDataPkgHierarchyLink(referencedValue);
return CapellaServices.getFullDataPkgHierarchyLink(referencedValue);
}
// Return empty if there is no value or if the type is not defined
return CapellaServices.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ private CapellaServices() {}
public static final String MAX = "MAX ";
public static final String DEFAULT = "DEFAULT ";
public static final String NULL = "NULL ";

public static final String NULL_LOWER_CASE = "null";

public static final String UNDEFINED = "undefined";
public static final String UNDEFINED_CHEVRON = "&lt;undefined&gt;";
Expand Down

0 comments on commit 529bfb3

Please sign in to comment.