#Java findbugs may expose internal.

12 messages · Page 1 of 1 (latest)

proud tulip
#
private final ApplicationPanel panel;

    public KeyboardInputs(final ApplicationPanel p) {
        this.panel = p;
    }
//this into ApplicationPanel
addKeyListener(new KeyboardInputs(this));

Im into the KeyboardInputs class.
this.panel = p; give me error may expose internal...

wide minnowBOT
#

This post has been reserved for your question.

Hey @proud tulip! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

echo fox
#

especially if stuff in your class is using the reference for private work, a client could change the objects properties and therefore change the private work done in the class which is a no no.

proud tulip
#

so how can I fix it?

#

How can I link them

echo fox
proud tulip
#

I have into KeyBoardInputs all the methods of keyeventListener

private final ApplicationPanel panel;

    public KeyboardInputs(final ApplicationPanel p) {
        this.panel= p;
    }

    @Override
    public void keyPressed(final KeyEvent key) {
        this.panel.getApplication().keyPressed(key);
    }
#

how can I link like this KeyBoardInputs and ApplicationPanel

quiet sparrow
#

well the application probably doesn't change, so see if you couldn't pass the application instead.
Otherwise you may have to first build the ApplicationPanel with its constructor, and only after bind a KeyboardInputs object to it. Nonideal, but that's how you avoid the encapsulation circumvention that findbug is complaining about.

proud tulip
#

it works passing directly the application instead of the panel and then getting application