summaryrefslogtreecommitdiffstats
path: root/test/003-omnibus-opcodes/src/InstField.java
blob: fe322b0668b48a739b6e106fd0d1f9200bab0d1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class InstField {
    public boolean mBoolean1, mBoolean2;
    public byte mByte1, mByte2;
    public char mChar1, mChar2;
    public short mShort1, mShort2;
    public int mInt1, mInt2;
    public float mFloat1, mFloat2;
    public long mLong1, mLong2;
    public double mDouble1, mDouble2;
    public volatile long mVolatileLong1, mVolatileLong2;

    public void run() {
        assignFields();
        checkFields();
        InstField.nullCheck(null);
    }

    /*
     * Check access to instance fields through a null pointer.
     */
    static public void nullCheck(InstField nully) {
        System.out.println("InstField.nullCheck");
        try {
            int x = nully.mInt1;
            Main.assertTrue(false);
        } catch (NullPointerException npe) {
            // good
        }
        try {
            long l = nully.mLong1;
            Main.assertTrue(false);
        } catch (NullPointerException npe) {
            // good
        }
        try {
            nully.mInt1 = 5;
            Main.assertTrue(false);
        } catch (NullPointerException npe) {
            // good
        }
        try {
            nully.mLong1 = 17L;
            Main.assertTrue(false);
        } catch (NullPointerException npe) {
            // good
        }
    }

    public void assignFields() {
        System.out.println("InstField assign...");
        mBoolean1 = true;
        mBoolean2 = false;
        mByte1 = 127;
        mByte2 = -128;
        mChar1 = 32767;
        mChar2 = 65535;
        mShort1 = 32767;
        mShort2 = -32768;
        mInt1 = 65537;
        mInt2 = -65537;
        mFloat1 = 3.1415f;
        mFloat2 = -1.0f / 0.0f;                // -inf
        mLong1 = 1234605616436508552L;     // 0x1122334455667788
        mLong2 = -1234605616436508552L;
        mDouble1 = 3.1415926535;
        mDouble2 = 1.0 / 0.0;               // +inf
        mVolatileLong1 = mLong1 - 1;
        mVolatileLong2 = mLong2 + 1;
    }

    public void checkFields() {
        System.out.println("InstField check...");
        Main.assertTrue(mBoolean1);
        Main.assertTrue(!mBoolean2);
        Main.assertTrue(mByte1 == 127);
        Main.assertTrue(mByte2 == -128);
        Main.assertTrue(mChar1 == 32767);
        Main.assertTrue(mChar2 == 65535);
        Main.assertTrue(mShort1 == 32767);
        Main.assertTrue(mShort2 == -32768);
        Main.assertTrue(mInt1 == 65537);
        Main.assertTrue(mInt2 == -65537);
        Main.assertTrue(mFloat1 > 3.141f && mFloat1 < 3.142f);
        Main.assertTrue(mFloat2 < mFloat1);
        Main.assertTrue(mLong1 == 1234605616436508552L);
        Main.assertTrue(mLong2 == -1234605616436508552L);
        Main.assertTrue(mDouble1 > 3.141592653 && mDouble1 < 3.141592654);
        Main.assertTrue(mDouble2 > mDouble1);
        Main.assertTrue(mVolatileLong1 == 1234605616436508551L);
        Main.assertTrue(mVolatileLong2 == -1234605616436508551L);
    }
}