Skip to content

Constructor with variable Array, with null value creates instance with one element  #778

@sergioszy

Description

@sergioszy

Hi,
With an object with the constructor type Myobject(Object ... params), with Java if you do new Myobject( null ) a null is passed to the constructor parameter and you have a null array and obviously without elements.
But with Bsh 3.0.0. latest version, with an object with the constructor type Myobject(Object ... params), if you do new Myobject( null ) a Myobject object is created with params type array of one element that is null.
Source:

package nova.test.bsh;

import bsh.EvalError;
import bsh.Interpreter;

public class TestBshArray {

public static void main(String[] args) {
	TestBshArray tb = new TestBshArray();
	tb.test();
}
public void test() {
	Interpreter interpreter22 = new Interpreter();
	Test test = new Test(null);
	/*
	 * Output = null:null
	 * 
	 */
	
	String str00 =  
			"import nova.test.bsh.Test;\n" +
			"Test test = new Test(null);\n";
	
	try {
		interpreter22.eval( str00 );
	} 
	catch (EvalError e2) {
		e2.printStackTrace();
	}

	/*
	 * Output = [Ljava.lang.Object;@4cc0edeb:1
	 * 
	 */

}

}

public class Test {

Object[] objects;

public Test( Object ...objects   ) {
	this.objects = objects;
	System.out.println( objects + ":" + (( objects != null )? objects.length : "null" ) );
}

}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions