Sunday, September 4, 2016

You're the top geeks on the world I'm very very proud to have you as my friends, I said this morning to you, I know something you don't know, but I don't remember what it is, Jesus doesn't want to me to remember and doesn't want me to say to you right now; I'm the google cracker :) the first 4 bytes, 4 imput class on a java object must match the firewall code;
"This means making the constructor private or default access ("package-private"), or being in a package controlled by the package.access security property. Immutable classes themselves should declare fields final and protect against any mutable inputs and outputs as described in Guideline 6-2. Construction of immutable objects can be made easier by providing builders (cf. Effective Java [6])."


http://www.oracle.com/technetwork/java/seccodeguide-139067.html#6 


How can I access a private constructor of a class?


One way to bypass the restriction is to use reflections:
import java.lang.reflect.Constructor;

public class Example {
    public static void main(final String[] args) throws Exception {
        Constructor<Foo> constructor = Foo.class.getDeclaredConstructor(new Class[0]);
        constructor.setAccessible(true);
        Foo foo = constructor.newInstance(new Object[0]);
        System.out.println(foo);
    }
}

class Foo {
    private Foo() {
        // private!
    }

    @Override
    public String toString() {
        return "I'm a Foo and I'm alright!";
    }
}

No comments:

Man in the Rain