GithubHelp home page GithubHelp logo

beanshell / beanshell Goto Github PK

View Code? Open in Web Editor NEW
824.0 46.0 183.0 15.67 MB

Beanshell scripting language

License: Apache License 2.0

Java 99.14% HTML 0.41% Shell 0.44% Batchfile 0.01%
java-shell java-interpreter scripting-language beanshell java beanshell-scripting-language

beanshell's Introduction

BeanShell - Simple Java Scripting

License Build workflow codecov coverity Known Vulnerabilities

The official and active project home for BeanShell.

NOTICE: Pending new release

The only reccomended version is a manual build of the master branch. Support for legacy releases reached end of line, only issues and pull requests against master can be accepted.

The next release will be BeanShell 3.0 as outlined in the development roadmap. It was decided that the next release will be a production ready major version with all outstanding issues resolved to encourage community envolvement and testing.

Most of the outstanding issues were imported from sourceforge, reported many years ago and now orphaned without owners. The majority will already be resolved in master, the valid ones need to be identified to the developers. An earnest call goes out for assistance in processing these issues to verify if they are still valid, reproducible or already resolved.

New language enhancement remain open for comments and discussion.

Items identified as out of scope for 3.0 are scheduled for the next release.

  • StrictJava compliance, unit tests and outstanding issues
  • Updated documentation. The discussions double as future documentation.

Introduction

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.

You can use BeanShell interactively for Java experimentation and debugging as well as to extend your applications in new ways. Scripting Java lends itself to a wide variety of applications including rapid prototyping, user scripting extension, rules engines, configuration, testing, dynamic deployment, embedded systems, and even Java education.

BeanShell is small and embeddable, so you can call BeanShell from your Java applications to execute Java code dynamically at run-time or to provide extensibility in your applications. Alternatively, you can use standalone BeanShell scripts to manipulate Java applications; working with Java objects and APIs dynamically. Since BeanShell is written in Java and runs in the same VM as your application, you can freely pass references to "live" objects into scripts and return them as results.

License

Starting with version 2.0b5, BeanShell is licensed under the Apache License, version 2.0. See LICENSE for details, and the NOTICE file for required attributions.

Download

Source code

The development snapshot branch is master, the currently recommended version for use. To build, pull the project and run the maven command.

$ mvn install

Requires as a minimum JDK 8 but will build with Java 9 and Java 10 as well.

The source code releases can be downloaded from GitHub releases

Latest release: not supported (use the recommended development snapshot)

Maven

Beanshell 3.0.0 currently only has a SNAPSHOT release published to sonatype. To use Beanshell with Maven, add this to your pom.xml:

    <dependencies>
       <dependency>
         <groupId>org.beanshell</groupId>
         <artifactId>bsh</artifactId>
         <version>3.0.0-SNAPSHOT</version>
       </dependency>
    </dependencies>

JAR binary

You can also download the bsh.jar binary from the releases page or the link below:

If you want to execute the Beanshell User Interface, either double-click the JAR file, or run it with:

$ java -jar bsh-2.1.1.jar

For a BeanShell interactive shell you can either use the java command:

$ java -cp bsh-2.1.1.jar bsh.Interpreter

or the supplied helper scripts bsh or bsh.bat available under the scripts folder.

You will need Java 5 or later installed.

Build

$ mvn clean install

Contribute

You are encouraged to raise a Github Pull Request with any suggested improvements and fixes!

You can also raise an issue for any questions or bugs. Remember, your stacktrace might be particularly useful for others!

Please note, only issues and pull requests made against the development branch merge-fork-beanshell2 will be considered.

Documentation

For full documentation, see the BeanShell wiki and the FAQ for frequently asked questions.

The old documentation available at http://beanshell.org may also be useful.

Summary of features

  • Dynamic execution of the full Java syntax, Java code fragments, as well as loosely typed Java and additional scripting conveniences.
  • Transparent access to all Java objects and APIs.
  • Runs in four modes: Command Line, Console, Applet, Remote Session Server.
  • Can work in security constrained environments without a classloader or bytecode generation for most features.
  • The interpreter is small, ~400K jar file.
  • Pure Java.
  • It's Free!!

Java evaluation features

  • Evaluate full Java source classes dynamically as well as isolated Java methods, statements, and expressions.

Scripting features

  • Optionally typed variables.
  • Scripted methods with optionally typed arguments and return values
  • Scripted objects (method closures)
  • Scripted interfaces and event handlers.
  • Convenience syntax for working with JavaBean? properties, hashtables, and primitive wrapper types.
  • Auto-allocation of variables to emulate Java properties files.
  • Extensible set of utility and shell-like commands
  • Dynamic classpath management including find grained class reloading
  • Dynamic command loading and user command path
  • Sophisticated namespace and callstack management
  • Detailed error reporting

BeanShell Uses

  • Interactive Java - try out object features, APIs and GUI widgets - "hands on".
  • Scripting extension for applications - Allow your applications to be extended via scripts in an intuitive and simple way.
  • Macro Languages - Generate scripts as macros and execute them live in your VM easily.
  • Education - Teach Java in a hands-on, live environment
  • Expression evaluator for scientific, financial apps and rules engines - evaluate complex expressions with conditions and loops.
  • Remote debugging - Embed a live, remotely accessible shell / command line in your application with just a few lines of code.
  • Use BeanShell declaratively to replace properties files and replace startup config files with real scripts that perform complex initialization and setup with the full Java syntax at their disposal.

Development road map

Current development effort is focused towards releasing BeanShell 3.0. The following road map serves as a guide to gauge progress to the next release.

  • Merge fork BeanShell2
  • Support for Java 9/10 with illegal access denied
  • Implement varargs
  • Implement try with resources
  • Implement multi-catch
  • Implement interfaces: constants, static and default methods
  • Implement generics parsing
  • Implement final modifier
  • Implement BigInteger/BigDecimal and number coercion
  • Make all current unit tests pass
  • Increase unit tests code coverage 70%
  • Resolve all outstanding issues and process pull requests
  • Apply uniform code style and javadocs
  • Consider feedback from community discussions

Projects using BeanShell

Projects that we know of which use BeanShell. Is your project not listed here? Let us know by submitting an issue.

History

2015: Move to github.com

On 2015-09-23, the BeanShell repository moved from https://code.google.com/a/apache-extras.org/p/beanshell/ to its new home on https://github.com/beanshell/beanshell/ as Google Code was been discontinued.

The project adapted an open collaborative approach using GitHub pull requests and has since grown its committer base beyond the original Apache Extra team.

http://beanshell.org/ remains available for older versions.

2012: Move to apache-extras.org

BeanShell was proposed as an incubator project to move to Apache Software Foundation. In preparation for this, the codebase for BeanShell 2.0b4 was donated to ASF by a code grant, and the license changed to Apache License, version 2.0.

The source code was moved to http://apache-extras.org/ - a project home hosted by Google Code, that was only informally associated with Apache Software Foundation. Many of the BeanShell committers were Apache committers, and thus Apache Extras seemed a natural home.

However the project did not move into the Apache incubator, and remained at apache-extras.org as an independent project.

In March 2015 Google announced it would discontinue Google Code, which provided the hosting for Apache Extras.

2007: Community fork beanshell2

The community forked BeanShell in May 2007 creating the BeanShell2 project hosted on google code. The new fork saw crucial fixes and updates with several releases between 2011 and 2014.

The project moved to GitHub in June 2016 after google code was discontinued and is independently maintained.

In August 2017 BeanShell decided to merge all the changes from the BeanShell2 fork back upstream ensuring that no effort was lost during this period.

2005: JSR 274: The BeanShell Scripting Language

In 2005 JSR 274 is accepted for officially defining the language but this was never completed. The current status is dormant as voted by the JCP in June 2011.

JSR 274: The BeanShell Scripting Language

1999: beanshell.org

BeanShell was originally developed by Patrick Niemeyer at http://beanshell.org/ - distributed as BeanShell (2.0b4 and earlier) were distributed under GNU Lesser General Public License (LGPL) and Sun Public License (SPL).

In 2000 the project was hosted on sourceforge which quickly saw interest in the new java scripting language grow.

beanshell's People

Contributors

charlie-cadmv avatar christian-cairney-sp avatar dependabot[bot] avatar drosenbauer avatar jimjag avatar jmetertea avatar mjwall avatar morris821028 avatar mreasy avatar n1ceh4t avatar nickl- avatar opeongo avatar patniemeyer avatar pgiffuni avatar pilot-pirx avatar smehrbrodt avatar stain avatar stefanofornari avatar tarcv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beanshell's Issues

execution of exec() internal

I have noticed that when place the following line in my bsh file that I get undesirable results:

exec( &quot;cat /myhome/contacts | grep test | grep -v grep | awk '{print $2}'&quot; );

Results

# This file is automatically generated during installation

Component Primary POC Secondary POC
------------------------------------------------------------------------

test [email protected] [email protected]

The results should be [email protected]. I have noticed this when I try to string commands together like in UNIX (Solaris) command line within my bsh files

Reported by: *anonymous

Original Ticket: "beanshell/bugs/4":https://sourceforge.net/p/beanshell/bugs/4

Swiss German keyboard doesn't work...

When trying to use it I discovered that the Swiss_German Keyboard of
my computer is not recognized. Using braces and other special symbols
is quite tedious right now.

Question: Am I doing something wrong or does beanshell have a problem
with Non US Keyboard layouts?

System:
NT4, Sun JDK 1.3

------------

I'm afraid this is very difficult for me to test, not having a system like this... Can anyone help?

I'm guessing this is a Java environment problem and probably not anything we can deal with directly... so I'm giving this a low priority for now.

Thanks,
Pat

Reported by: patn

Original Ticket: "beanshell/bugs/10":https://sourceforge.net/p/beanshell/bugs/10

^ operator not implemented yet.

Using the XOR (^) operator makes the interpreter throw an bsh.InterpreterError with the message &quot;unimplemented binary operator&quot;.

Since you already seem to have taken note of the fact that the XOR operator exists (by throwing the exception), I suppose this is just a reminder to implement it. :)

Reported by: amc1

Original Ticket: "beanshell/bugs/21":https://sourceforge.net/p/beanshell/bugs/21

Multi-dim array initializers incomplete...

On Sun, Aug 27, 2000 at 02:05:35PM +1000, ruki monster wrote:
&gt; you can't do this in BeanShell:
&gt;
&gt; Object o[][]={ {&quot;me&quot;,new Integer(5),new Byte(3)},
&gt; {&quot;you&quot;,new Integer(6),new Byte(2)}};

Yes, that needs to be fixed.

I should note that it does work if you add the base type of the inside
arrays (which is legal in Java as well) e.g:

Object o[][]={ new Object [] {&quot;me&quot;,new Integer(5),new Byte(3)},
new Object [] {&quot;you&quot;,new Integer(6),new Byte(2)}};

Reported by: patn

Original Ticket: "beanshell/bugs/8":https://sourceforge.net/p/beanshell/bugs/8

Proxy interface missing Object methods

In XThis.java, the invoke() method of the Handler class does not implement the Object protocol. I think that it should. The particular method that I'm missing is hashCode() (and probably equals(), but I haven't gotten that far yet), but I think it should do the right thing for all the Object methods.

The code that I used to find this was:

toolkit = java.awt.Toolkit.getDefaultToolkit();
handler = (java.awt.event.AWTEventListener)this;
toolkit.addAWTEventListener(handler, 0x20);

I wanted to track the mouse position so that I could control it with a java.awt.Robot.

For now, I can work around the bug by writing the methods I need, but I think Beanshell should do this for me.

My reading of the documentation implies that I shouldn't need the explicit cast to java.awt.AWTEventListener, but it didn't work otherwise.

Reported by: *anonymous

Original Ticket: "beanshell/bugs/24":https://sourceforge.net/p/beanshell/bugs/24

eval() side effects in wrong namespace

The current implementation of the eval(String) command
does not have a way to determine the namespace of the
caller... It currently uses the global namespace and
that is where side effects will appear (e.g. eval
(&quot;a=5&quot;);)

To fix this I'm considering adding a this.caller magic
field that will always hold a This ref to the calling
context.

--Pat

Reported by: patn

Original Ticket: "beanshell/bugs/32":https://sourceforge.net/p/beanshell/bugs/32

Invoking non-static methods on a class.

If you try to perform the following line of code:

ArrayList.add (new Object());

A null-pointer exception is thrown. Now of course,
since the add method is not static, this method is
bound to fail. However, the interpreter should
probably return some meaningful message to indicate
this is the situation, rather than throwing
the &quot;Unknown error&quot; message.

Reported by: amc1

Original Ticket: "beanshell/bugs/25":https://sourceforge.net/p/beanshell/bugs/25

Access last thrown exception

I would like to be able to access the last thrown
exception. For example, when I have something like
this:
bsh% myVar.myMethod(&quot;arg&quot;);

// Error: // Uncaught Exception: TargetError : at
Line: 66 : in file: &lt;unknown file&gt; : myVar.myMethod
(&quot;arg&quot;)
Target exception: org.xml.sax.SAXParseException:
Illegal XML character: &amp;#x8;.

(Or whatever the exception is)

Now, I'd like to be able to examine that exception, do
a stack trace, etc., but that exception is gone unless
I happened to expect it and throw the thing to be
evaluated into a try{}.

I'd like some way while in interactive mode to access
the exception that caused the most recent Error
message.

Reported by: fizbin

Original Ticket: "beanshell/bugs/43":https://sourceforge.net/p/beanshell/bugs/43

interfaces returning primitives

Currenty it is not possible to implement interfaces
that return primitives types, as the following example
suggests:

----
Java Interface:
public interface C_i
{
public int test_P( int x );
}

Java Testclass:
public class C
{
public void test( C_i x ) {
System.out.println( x.test_P( 42 ) );
}
}

Beanshell script:
C c = new C();

int test_P( int x ) { return 2*x; }

c.test( this );
----

This will throw a ClassCastException!

Here's the cvs diff of a possible fix:
(basically, if the return type a primitive type it is
&quot;unwrapped&quot;)

lars@pionier:/opt/BeanShell$ cvs diff
? classes
? bsh.jar
cvs server: Diffing .
cvs server: Diffing scripts
cvs server: Diffing src
cvs server: Diffing src/bsh
Index: src/bsh/XThis.java

RCS file:
/cvsroot/beanshell/BeanShell/src/bsh/XThis.java,v
retrieving revision 1.6
diff -r1.6 XThis.java
108a109,110
&gt; Object result;
&gt;
113,115c115,122
&lt; if ( bmethod != null )
&lt; return
bmethod.invokeDeclaredMethod(
&lt; args,
declaringInterpreter );
---
&gt; if ( bmethod != null ) {
&gt; result =
bmethod.invokeDeclaredMethod(
&gt; args,
declaringInterpreter );
&gt; if( result instanceof
Primitive &amp;&amp; ((Primitive)result).getType() != null )
&gt; result =
((Primitive)result).getValue();
&gt;
&gt; return result;
&gt; }
122,125c129,137
&lt; if ( bmethod != null )
&lt; return
bmethod.invokeDeclaredMethod(
&lt; new Object [] {
method.getName(), args },
&lt;
declaringInterpreter );
---
&gt; if ( bmethod != null ) {
&gt; result =
bmethod.invokeDeclaredMethod(
&gt; new Object
[] { method.getName(), args },
&gt;
declaringInterpreter );
&gt; if( result instanceof
Primitive &amp;&amp; ((Primitive)result).getType() != null )
&gt; result =
((Primitive)result).getValue();
&gt;
&gt; return result;
&gt; }
cvs server: Diffing src/bsh/classpath
cvs server: Diffing src/bsh/commands
cvs server: Diffing src/bsh/lib
cvs server: Diffing src/bsh/util
cvs server: Diffing src/bsh/util/lib
cvs server: Diffing tests
cvs server: Diffing tests/Data
cvs server: Diffing tests/Interactive
cvs server: Diffing tests/Interactive/reload
cvs server: Diffing tests/Misc
cvs server: Diffing tests/classes
cvs server: Diffing tests/classes/InheritanceTest
cvs server: Diffing tests/classes/mypackage

Thanks,

Lars

Reported by: hofhansl

Original Ticket: "beanshell/bugs/37":https://sourceforge.net/p/beanshell/bugs/37

Primitive results from proxy invocations

If a method in a proxy interface returns a primitive result, it needs to be coerced to a java wrapper class.

The invoke() method in XThis.java uses invokeDeclaredMethod() to call the user method, and then simply returns that result. If it is a primitive value, it will be BeanShell's wrapper for the primitive instead of Java's.

A workaround is to do the Java wrapping in the method code, but this doesn't make sense to me.

For example, the following works:

toolkit = java.awt.Toolkit.getDefaultToolkit();
handler = (java.awt.event.AWTEventListener)this;
hashCode = new Integer(12);
hashCode() { return hashCode; }
equals(Object o) {
return (o == handler) ?
Boolean.TRUE : Boolean.FALSE;
}
toolkit.addAWTEventListener(handler, 0x20);

But I think I should be able to write this code as:

toolkit = java.awt.Toolkit.getDefaultToolkit();
handler = (java.awt.event.AWTEventListener)this;
hashCode = 12;
hashCode() { return hashCode; }
equals(Object o) {
return o == handler;
}
toolkit.addAWTEventListener(handler, 0x20);

I also think I shouldn't have to write the hashCode() and equals() methods at all, but I reported that as bug #408502.

Reported by: shakerwws

Original Ticket: "beanshell/bugs/27":https://sourceforge.net/p/beanshell/bugs/27

Array initializer may not contain null

x = new String[] {null, &quot;foo&quot;} gets the following error in bsh-1.01:

java.lang.NullPointerException at java.lang.reflect.Array.newArray(Native Method) at java.lang.reflect.Array.newInstance(Array.java:54) at bsh.BSHArrayInitializer.eval(BSHArrayInitializer.java:47) at bsh.BSHArrayDimensions.eval(BSHArrayDimensions.java:48) at bsh.BSHArrayDimensions.eval(BSHArrayDimensions.java:36) at bsh.BSHAllocationExpression.objectArrayAllocation(BSHAllocationExpression.java:82) at bsh.BSHAllocationExpression.eval(BSHAllocationExpression.java:40) at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:48)
The problem appears to be in BSHArrayInitializer.eval(). It should probably use the &quot;baseType&quot; input parameter instead of the type of the first initializer as the type for the &quot;initializers&quot; array.

Reported by: shakerwws

Original Ticket: "beanshell/bugs/35":https://sourceforge.net/p/beanshell/bugs/35

incorrect scoping in for loops

See the attached file which demonstrates the bug.

Basically beanshell assumes that any variable
initialised in a for loop is declared in that loop
(because of untyped declarations) and hence is only
local scope. This means it is inconsistent with java.

In java the following code would print 2, but in
beanshell it prints 5.
int i = 5;
for(int i=0; i&lt;2; i++)
;
System.out.println(i);

for needs additional checks on whether variables are
already declared before it rescopes them.

Reported by: *anonymous

Original Ticket: "beanshell/bugs/31":https://sourceforge.net/p/beanshell/bugs/31

new Object[]{null};

bsh % new Object[]{null};
// Error: Unknown error: java.lang.NullPointerException

workaround:
Object[] obs= new Object[3];
obs[0]= null;
obs[1]= new Object();
obs[2]= null;

If all you want is an array of nulls, then there is no
issue... simply use new Object[size];
...but if some of the elements should be not null, you
have to set the nulls separately.

Reported by: *anonymous

Original Ticket: "beanshell/bugs/39":https://sourceforge.net/p/beanshell/bugs/39

System.out handling

Many things, not just poorly written debugging code,
write to System.out and/or System.err. It would be
nice to have access to those streams when, for
example, working under Windows with the bsh GUI
console.

While I can do a
java.lang.System.setOut(this.interpreter.getOut());
java.lang.System.setErr(this.interpreter.getErr());
in my %USERPROFILE%/.bshrc, this has the problem that
a System.out() from different workspaces all end up in
the last workspace window I opened - this means that
quickly opening a new workspace and then closing it
(say to check some side calculation) has the side
effect of sending your output off to nowhere.

I want a PrintStream that will direct to the
appropriate Interpreter's output. I could then do:

java.lang.System.setOut(bsh.Interpreter.getGlobalOut
());
java.lang.System.setErr(bsh.Interpreter.getGlobalErr
());

in my .bshrc and have the GUI console windows behave
as one would expect them to.

Failing that, I'd like to have separate windows for
System.out and System.err -- at least then I won't
accidentally lose all of the output by opening up a
new workspace and closing it, even if I do have the
problem of having all the outputs comingled.

Reported by: fizbin

Original Ticket: "beanshell/bugs/44":https://sourceforge.net/p/beanshell/bugs/44

'cd \' causes infinite loop

For those of us who start up bsh.Console under Windows and want to try a cd command, typing 'cd ;' causes an infinite loop. Yes, that's not even good syntax, but still, for novices who are playing around, it would be better not to loop.

Thanks!

Reported by: *anonymous

Original Ticket: "beanshell/bugs/17":https://sourceforge.net/p/beanshell/bugs/17

Assigning 'long' numbers inconsistency.

Might not be a bug, maybe I'm just missing something
really obvious, but follow this:

bsh % l = System.currentTimeMillis();
bsh % print(l);
1007133360712
bsh % l = 1007133199549;
// Error: Unknown error:
java.lang.NumberFormatException: 1007133199549
bsh % bsh % print(&quot;eek&quot;);
eek
bsh %

Doesn't matter if you type to 'long'. Just seems wrong
to me. Love bsh btw. I'm currently examining the
EvalError code to figure out how to put in the ability
to extract an error number as well as an error string
for embedded interpreting to catch things that fail.
Maybe in two weeks though, as I'm off to Scotland for
a holiday... Och eye the noo!

Reported by: kimberleyscott

Original Ticket: "beanshell/bugs/45":https://sourceforge.net/p/beanshell/bugs/45

Multi-dim array initializers incomplete...

On Sun, Aug 27, 2000 at 02:05:35PM +1000, ruki monster wrote:
&gt; you can't do this in BeanShell:
&gt;
&gt; Object o[][]={ {&quot;me&quot;,new Integer(5),new Byte(3)},
&gt; {&quot;you&quot;,new Integer(6),new Byte(2)}};

Yes, that needs to be fixed.

I should note that it does work if you add the base type of the inside
arrays (which is legal in Java as well) e.g:

Object o[][]={ new Object [] {&quot;me&quot;,new Integer(5),new Byte(3)},
new Object [] {&quot;you&quot;,new Integer(6),new Byte(2)}};

Reported by: patn

Original Ticket: "beanshell/bugs/7":https://sourceforge.net/p/beanshell/bugs/7

Workspace error msgs and class browser

With J2SE 1.4b3, WinXP
Start the class browser from the bsh% prompt
using &quot;classBroswer();&quot; When closing the classbrowser
window, the workspace starts spitting out the
following error message repeatedly until I the
workspace window is closed.
bsh % // Error: Command not found: lassBrowser:
&lt;at unknown location&gt;

Reported by: dwette

Original Ticket: "beanshell/bugs/48":https://sourceforge.net/p/beanshell/bugs/48

Example on your homepage

I think the example on your homepage should look like
the one below.

I added a new line:
import bsh.util.BshCanvas; // BshCanvas simply

and changed the line:
g.plot( x, y, Color.black );

I think this will make things easier for BeanShell
beginners.

-----
import bsh.util.BshCanvas; // BshCanvas simply
buffers graphics

graph( int width, int height ) {
object() { return this; } // this will be a
global method in 0.92
scale=object();
scale.x=100; scale.y=100;

drawAxis() {
graphics.setColor( Color.red );
graphics.drawLine( 0, height/2, width,
height/2 );
graphics.drawLine( width/2, 0,
width/2, height );
}

plot(x, y, Color color) {
graphics.setColor( color );
graphics.fillOval( (int)((x/scale.x+1)*
(width/2))-1,
(int)((-y/scale.y+1)*
(height/2))-1, 3, 3);
canvas.repaint();
}

clear() {
graphics.setColor( Color.white );
graphics.fillRect(0,0,width,height);
drawAxis();
canvas.repaint();
}

setScale( x, y ) {
scale.x=1.0*x;
scale.y=1.0*y;
}

canvas=new BshCanvas(); // BshCanvas simply
buffers graphics
canvas.setSize( width, height );
frame=frame( canvas );
graphics=canvas.getBufferedGraphics();
drawAxis();

return this;
}

g=graph(400,200);
g.setScale(2*Math.PI,1.0);
for (x=-2*Math.PI; x&lt;2*Math.PI; x+=0.1) {
y=Math.sin(x);
g.plot( x, y, Color.black );
}

--
Klaus Hartlage
webmaster at hartmath.org
http://www.jsurfer.org - slash like java news and
resources

Reported by: *anonymous

Original Ticket: "beanshell/bugs/41":https://sourceforge.net/p/beanshell/bugs/41

Console caret disappears on new win

JDK 1.3, Win98SE. When I right-click the desktop and bring up a new window, the text insertion cursor (caret) disappears from the workspace window. When the newly opened window is a new workspace window, neither it nor the previous one show a caret. Switching to a different Windows app then back to Bsh restores the caret; switching between workspace windows makes it disappear again.

Bewildered,

Reported by: *anonymous

Original Ticket: "beanshell/bugs/12":https://sourceforge.net/p/beanshell/bugs/12

equality comparison inconsistency

Comparison of primitive wrapper objects using &quot;==&quot;
behaves inconsistently.

Consider the following example:

bsh % a = new Integer(1);
bsh % b = new Integer(1);
bsh % c = new Long(1);
bsh % print (a == b);
false
bsh % print (a == c);
false
bsh % print (c == a);
false
bsh % d = new Double(1);
bsh % print (a == d);
true
bsh %

Identity comparison for various wrapper objects around
the same value return false (which is correct
according to Java, although non-intuitive for a
scripting language). But the same comparison between
an Integer and a Double returns true.

Reported by: *anonymous

Original Ticket: "beanshell/bugs/46":https://sourceforge.net/p/beanshell/bugs/46

!s1.equals(s2) not supported

i.set(&quot;x&quot;, 10);
i.set(&quot;y&quot;,5);
i.set(&quot;s1&quot;,&quot;MY &quot;);
i.set(&quot;s2&quot;,&quot;STRING&quot;);
Object obj = i.eval(&quot;!s1.equals(s2)&quot;);
System.out.println(&quot;Object = &quot; + obj);

returns invalid expression

Reported by: *anonymous

Original Ticket: "beanshell/bugs/33":https://sourceforge.net/p/beanshell/bugs/33

Slowness in BeanShell

ii=0;
for ( ; ii &lt; 10000; ii++)
{
}
print (&quot;after the loop:&quot; + ii);
This is quite a bit slower in BeanShell than in other programs.
Looking at the source code, I suspect that the problem is not
in the loop but in variable handling. Specifically the follwing:
private Object consumeNextObjectField( Interpreter interpreter )
throws EvalError
{
/*
Is it a class name?
If we're just starting eval of name (and it wasn't a variable
reference per above) try to make it, else fail.
Class names are attempted before long variable chains because
we don't have any way to &quot;back out&quot; if we start down a chain
and we're wrong. In general this seems ok.
*/
So each time ii is looked at BeanShell checks to see if it's a class or
a variable, and that takes time.

Reported by: drormata

Original Ticket: "beanshell/bugs/20":https://sourceforge.net/p/beanshell/bugs/20

s = &quot;\1&quot;;

This works:

bsh % s = &quot;\1a\1a&quot;;
bsh % print(s);
?a?a

This doesn't:

bsh % s = &quot;\1&quot;;

// Error: Unknown error: java.lang.StringIndexOutOfBoundsException: String index out of range: 2
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.charAt(Unknown Source)
at bsh.BSHLiteral.stringSetup(BSHLiteral.java:118)
at bsh.Interpreter.Literal(Interpreter.java:2920)
at bsh.Interpreter.PrimaryPrefix(Interpreter.java:2601)
at bsh.Interpreter.PrimaryExpression(Interpreter.java:2552)
at bsh.Interpreter.PostfixExpression(Interpreter.java:2452)
at bsh.Interpreter.UnaryExpressionNotPlusMinus(Interpreter.java:2368)
at bsh.Interpreter.UnaryExpression(Interpreter.java:2266)
at bsh.Interpreter.MultiplicativeExpression(Interpreter.java:2166)
at bsh.Interpreter.AdditiveExpression(Interpreter.java:2121)
at bsh.Interpreter.ShiftExpression(Interpreter.java:2060)
at bsh.Interpreter.RelationalExpression(Interpreter.java:1991)
at bsh.Interpreter.InstanceOfExpression(Interpreter.java:1962)
at bsh.Interpreter.EqualityExpression(Interpreter.java:1917)
at bsh.Interpreter.AndExpression(Interpreter.java:1872)
at bsh.Interpreter.ExclusiveOrExpression(Interpreter.java:1839)
at bsh.Interpreter.InclusiveOrExpression(Interpreter.java:1794)
at bsh.Interpreter.ConditionalAndExpression(Interpreter.java:1749)
at bsh.Interpreter.ConditionalOrExpression(Interpreter.java:1704)
at bsh.Interpreter.ConditionalExpression(Interpreter.java:1663)
at bsh.Interpreter.Expression(Interpreter.java:1561)
at bsh.Interpreter.Assignment(Interpreter.java:1581)
at bsh.Interpreter.Expression(Interpreter.java:1541)
at bsh.Interpreter.Line(Interpreter.java:830)
at bsh.Interpreter.run(Interpreter.java:329)
at bsh.Interpreter.main(Interpreter.java:294)

Reported by: *anonymous

Original Ticket: "beanshell/bugs/34":https://sourceforge.net/p/beanshell/bugs/34

polymorphic methods - runtime vs. declared types

Hi,

The following piece of code should illustrate the
problem. Both invocations of test print out "I am an
integer". For the o1 case, this is not too important
(even though it means that BeanShell is not consistent
to Java in that respect), but the o2 case is probably
more important than the first.

-- CLASS DEFINITION --

public class Test {
    public void test (Object o) {
        System.out.println ("I am a generic object.");
    }
    public void test (Integer f) {
        System.out.println ("I am an integer.");
    }
}

-- EXECUTION SCRIPT --

Object o1 = new Integer (5);
Object o2 = null;
new Test().test(o1);
new Test().test(o2);

Allan.

Reported by: amc1

Original Ticket: "beanshell/bugs/29":https://sourceforge.net/p/beanshell/bugs/29

array initializer; different types

bsh % ArrayList l= new ArrayList();
bsh % LinkedList l2= new LinkedList();
bsh % List[] la= new List[]{l,l2};
// Error: Incompatible types in initializer.
Initializer contains both java.util.ArrayList and
java.util.LinkedList

workaround:
set array elements individually

p.s. I also submitted one today about null not being
accepted in an array initializer.

Reported by: dsmiley

Original Ticket: "beanshell/bugs/40":https://sourceforge.net/p/beanshell/bugs/40

array initializer with different types

I got the following messages:
beanshell 1.1a9 - by Pat Niemeyer ([email protected])
bsh % Object[] test = new Object[] { new Long(2000),
&quot;MyDisk&quot;, new Double(21.4) };
// Error: Incompatible types in initializer.
Initializer contains both java.lang.Long and
java.lang.String

Is this for the same reason as the bug #424928 ?
I thought this would be only a problem for multi-dim
array as Pat wrote in #212841 .
However, javac takes this without complaining.

Even this did not work:
Object[] test2 = new Object[] { (Object)new Long(2000),
(Object)&quot;MyDisk&quot;, (Object)new Double(21.4) };
// Error: Incompatible types in initializer.
Initializer contains both java.lang.Long and
java.lang.String

Reported by: limpus

Original Ticket: "beanshell/bugs/38":https://sourceforge.net/p/beanshell/bugs/38

Reduce beanshell footprint

I noticed that a large percentage of the beanshell footprint is devoted to the JavaCC lexer and grammar.
The lex footprint could be reduced by using JFlex or another lex; the grammar footprint can be reduced by applying the optimization techniques described in the JavaCC doc (can't find the reference, says something
about optimizing).

Reported by: fredthegorilla

Original Ticket: "beanshell/feature-requests/1":https://sourceforge.net/p/beanshell/feature-requests/1

Reduce beanshell footprint

I noticed that a large percentage of the beanshell footprint is devoted to the JavaCC lexer and grammar.
The lex footprint could be reduced by using JFlex or another lex; the grammar footprint can be reduced by applying the optimization techniques described in the JavaCC doc (can't find the reference, says something
about optimizing).

Reported by: fredthegorilla

Original Ticket: "beanshell/feature-requests/1":https://sourceforge.net/p/beanshell/feature-requests/1

classpath reload failure

when starting bsh with rt.jar in the classpath (eg:
java -classpath c:\java\jdk\jre\lib\rt.jar;bsh.jar
bsh.Interpreter), I cannot use internal functions like
print(), source(), exit()... after doing a
reloadClasses();

I always get a security exception.

If a remove rt.jar from the classpath, everything
works perfectly.

here's the trace:

// Error: Unknown error: java.lang.SecurityException:
Prohibited package name: java.lang
java.lang.SecurityException:
Prohibited package name: java.lang
at java.lang.ClassLoader.defineClass
(ClassLoader.java:477)
at java.security.SecureClassLoader.defineClass
(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass
(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100
(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run
(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged
(Native Method)
at java.net.URLClassLoader.findClass
(URLClassLoader.java:188)
at bsh.classpath.BshClassLoader.findClass
(BshClassLoader.java:140)
at bsh.classpath.BshClassLoader.loadClass
(BshClassLoader.java:90)
at java.lang.ClassLoader.loadClass
(ClassLoader.java:253)
at bsh.BshClassManager.getClassForName
(BshClassManager.java:147)
at bsh.BshClassManager.classForName
(BshClassManager.java:402)
at bsh.NameSpace.classForName
(NameSpace.java:479)
at bsh.NameSpace.getClassImpl
(NameSpace.java:449)
at bsh.NameSpace.getClass(NameSpace.java:390)
at bsh.Name.toClass(Name.java:304)
at bsh.BSHAmbiguousName.toClass
(BSHAmbiguousName.java:56)
at bsh.BSHType.getType(BSHType.java:70)
at bsh.BSHBinaryExpression.eval
(BSHBinaryExpression.java:65)
at bsh.BSHIfStatement.evaluateCondition
(BSHIfStatement.java:62)
at bsh.BSHIfStatement.eval
(BSHIfStatement.java:45)
at bsh.BSHBlock.eval(BSHBlock.java:49)
at bsh.BshMethod.invokeDeclaredMethod
(BshMethod.java:127)
at bsh.Name.invokeLocalMethod(Name.java:527)
at bsh.Name.invokeMethod(Name.java:439)
at bsh.BSHMethodInvocation.eval
(BSHMethodInvocation.java:48)
at bsh.BSHPrimaryExpression.eval
(BSHPrimaryExpression.java:67)
at bsh.Interpreter.run(Interpreter.java:334)
at bsh.Interpreter.main(Interpreter.java:290)

Reported by: *anonymous

Original Ticket: "beanshell/bugs/42":https://sourceforge.net/p/beanshell/bugs/42

Proxy interface missing Object methods

In XThis.java, the invoke() method of the Handler class does not implement the Object protocol. I think that it should. The particular method that I'm missing is hashCode() (and probably equals(), but I haven't gotten that far yet), but I think it should do the right thing for all the Object methods.

The code that I used to find this was:

toolkit = java.awt.Toolkit.getDefaultToolkit();
handler = (java.awt.event.AWTEventListener)this;
toolkit.addAWTEventListener(handler, 0x20);

I wanted to track the mouse position so that I could control it with a java.awt.Robot.

For now, I can work around the bug by writing the methods I need, but I think Beanshell should do this for me.

My reading of the documentation implies that I shouldn't need the explicit cast to java.awt.AWTEventListener, but it didn't work otherwise.

Reported by: *anonymous

Original Ticket: "beanshell/bugs/23":https://sourceforge.net/p/beanshell/bugs/23

No endorsed packages in class browser

The class browser does not display overriding
endorsed packages with J2SE 1.4b3. See
http://java.sun.com/j2se/1.4/docs/guide/standards/inde
x.html

For example, if I place the latest Apache xerces,
xalan, and jaxp-api jar files in the
$JAVA_HOME/jre/lib/endorsed directory, the class
browser still reveals only the original org.apache.*
classes for crimson and xalan, archived in rt.jar ,
rather than the newer, overriding ones.

Reported by: dwette

Original Ticket: "beanshell/bugs/47":https://sourceforge.net/p/beanshell/bugs/47

Byte / Int intepretation

The following line
byte b = 0x00;

Is valid java, but you get the following message:
Error: Can't assign int to byte

I would try to find the problem if I could, but I think the Interpreter class would have to be split up more before I could begin to understand it.... :)

Allan.

Reported by: amc1

Original Ticket: "beanshell/bugs/19":https://sourceforge.net/p/beanshell/bugs/19

Ternary operator bug...

&gt; The following syntax breaks:
&gt;
&gt; (glick &lt;= 5) ? 1 : 0;
&gt;
&gt; I believe because of the &lt;= operator. The following works ok:
&gt;
&gt; (glick &lt; 5) ? 1 : 0;
&gt;
&gt; I suspect that the == op has problems as well, as do any of the ops
&gt; that use the = sign. Just a guess.

Reported by: patn

Original Ticket: "beanshell/bugs/5":https://sourceforge.net/p/beanshell/bugs/5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.