Skip to content

And expression that contains a function that returns a boolean always evaluates to false #2

@caojunliangAlex

Description

@caojunliangAlex

Problem:
Assume that s is a string.
expression : s.contains("a") && s.contains("b")
The result is always false.

The "toBoolean" method of class "com.greenpineyu.fel.function.operator.And" need some improvement.

public String toBoolean(FelNode node, FelContext ctx, int index) {
	List<FelNode> children = node.getChildren();
	FelNode child = children.get(index);
	SourceBuilder method = child.toMethod(ctx);
	Class<?> type = method.returnType(ctx, child);

            //problem is here,primitive type boolean is not included.
	if (Boolean.class.isAssignableFrom(type) ||  boolean.class.isAssignableFrom(type)) {
		return "(" + method.source(ctx, child) + ")";
	}
	if (String.class.isAssignableFrom(type)) {
		return "Boolean.valueOf(" + method.source(ctx, child) + ")";
	}
	if (Null.class.isAssignableFrom(type)) {
		return "false";
	}
	return "false";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions