3

I am trying to run the following Beanshell code--

assignee.toString()!=''

Here 'assignee' is a variable in Beanshell context.

But I am getting the following error--

Caused by: Sourced file: inline evaluation of: ``assignee.toString()!='';'' Token Parsing Error: Lexical error at line 1, column 23.  Encountered: "\'" (39), after : "\'": <at unknown location>

at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at org.webharvest.runtime.scripting.BeanShellScriptEngine.eval(BeanShellScriptEngine.java:104)

What am I doing wrong here? I want to check if the variable 'assignee' has a null value or not... What is the correct way of accomplishing this?

Arvind
  • 6,404
  • 20
  • 94
  • 143

2 Answers2

1

The issue is that 'c' is a character literal, but '' (a character literal for "no character"?) is invalid Java syntax. (Even if it did parse there would be a type error with String == char.)

Perhaps "" (an empty String) literal was meant instead?

Important Note: even if this doesn't have a Syntax Error one should generally not compare Strings with == (or !=) as the results can be unexpected.. There are plenty of questions on SO as to why and how to properly compare String objects in Java: e.g. see String.equals(..) and String.isEmpty().

Happy coding!

0

Compare it directly to null:

if(assignee.toString() != null)
{
   do.something();
}
blearn
  • 1,198
  • 10
  • 17