Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:43+00:00 2026-06-17T09:26:43+00:00

Why does not jsr-223 evaluate string when is a attribute of a object? Simple

  • 0

Why does not jsr-223 evaluate string when is a attribute of a object?

Simple class with only one String attribute:

public class EvalJSR223Bean {
    public String evalFnt;
}

Simple evaluation using text and object, and when is used the object, Rhino does not execute eval. But if I concatenate empty javascript string to object property, Rhino eval.

public static void main(String[] args) throws ScriptException {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("JavaScript");


    engine.eval("function f2() {println('EXECUTED!!!!!')}; function f1(source) {  return eval(source); };");


    String evalFnt = "(function(){f2();return '0';})();";
    engine.put("evalFnt", evalFnt);
    engine.eval("f1(evalFnt);"); // f2 is executed.


    EvalJSR223Bean bean = new EvalJSR223Bean();
    bean.evalFnt = evalFnt;


    engine.put("bean1", bean.evalFnt);
    engine.eval("f1(bean1.evalFnt);"); // Why does NOT executed f2 ?!!.

    engine.put("bean", bean);
    engine.eval("f1(bean.evalFnt);"); // Why does NOT executed f2 ?!!.

    engine.put("bean", bean);
    engine.eval("f1( ''+bean.evalFnt );"); // And if I concatenate a string, f2 is executed!!!
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:26:44+00:00Added an answer on June 17, 2026 at 9:26 am

    eval ignores the string if the string is not of type “string”:

    eval(new String('console.log("foo");'));
    

    So this is likely a consequence of how Rhino treats the property as being of type “object”. When you put a string into the engine, it must convert it to the value type.

    This code:

    import javax.script.*;
    
    public class ScriptDemo {
      public static class Bar {
        public String bar = "bar";
      }
    
      public static void main(String[] args) throws ScriptException {
        ScriptEngine engine =
                             new ScriptEngineManager().getEngineByName("JavaScript");
        engine.put("foo", "foo");
        engine.put("bar", new Bar());
        engine.eval("println(typeof foo);");
        engine.eval("println(typeof bar.bar);");
        engine.eval("println(typeof String(bar.bar));");
        engine.eval("println(typeof new String(bar.bar));");
      }
    }
    

    Output:

    string
    object
    string
    object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does not work Attribute.GetCustomAttribute : using System; class Program { static void Main() {
It does not seem that SendGrid has a free account that one could use
I have this class @HasNose @HasMouth public class Person { String fieldA; String fieldB;
does not work (Compilation error: missing return statement) public SqlMapClientTemplate getSqlTempl() throws UivException, SQLException{
show() does not work http://jsfiddle.net/Pppy6/5/ <div class=hello id=hello>2<div class=ola id=ola>showMe!</div></div> .ola { display:none }​
It does not seem straighforward. I am trying this: @Override public int compare(Period o1,
I have a simple bean with enum field public class TestBean{ @Pattern(regexp = A|B)
This does not work, and outputs an empty string: $check[pattern] = correct; $text =
This does not work, even though putting a simple print (foo) in the function
Yacc does not permit objects to be passed around. Because the %union can only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.