Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized array positions #6

Open
manuelmontenegro opened this issue Sep 11, 2014 · 0 comments
Open

Uninitialized array positions #6

manuelmontenegro opened this issue Sep 11, 2014 · 0 comments
Labels

Comments

@manuelmontenegro
Copy link
Contributor

Given the following Java method (can be found in IntegerDivision: 9fe4389 ):

    public int simpleArray(int x) {
        int[] numbers = {x,0};
        return numbers[1];
    }

The javac compiler (openjdk: javac 1.6.0_24) generates the following bytecode:

00:  iconst_2
; Array initialization:
01:  newarray  10
03:  dup
04:  iconst_0
05:  iload_1
06:  iastore
; Return numbers[1]:
07:  astore_2
08:  aload_2
09:  iconst_1
10:  iaload
11:  ireturn

Only the zero-th position of the array is initialized. The first one is not, as JVM's newarray specification specifies the following: Each of the elements of the new array is initialized to the default initial value (§2.3, §2.4) for the element type of the array type.
[Taken from: http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.newarray]

So, there is no need to initialize numbers[1] explicitly in the JVM code. However, Muggl initializes numbers[1] to null. As a consequence, null is returned in a method that should return an int. This generates the following test case, which is ill-typed:

        this.reference0 = null;
                ...
        assertEquals(this.reference0, this.testedClass.simpleArray(this.int1));
@Dagefoerde Dagefoerde added the bug label Sep 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants