Access to private fields without validation bytecode

An example is taken from the Java security book O'Reilly.

There are two classes of Card.java

public class Card {
    public int num = 123234;
}

and Test.java

public class Test {
    public static void main(String[] args) {
        Card card = new Card();
        System.out.println("Your card - " + card.num);
    }
}

I am compiling both classes using Java 1.2 . Then I change the field modifier numto private and recompile only the class Card.

Running a test (java Test) class produces the following output.

Your card is 123234.

Thus, it worked even without disabling the bytecode verifier (although the author says that if we were not a bytecode verifier, it would work).

Now I am doing the same with Java 1.6 . Running the Test class produces IllegalAccessError, even if I start it with -noverify.

Questions:

1) - . , .

2) Java?

+4
1
+3

All Articles