checker-framework icon indicating copy to clipboard operation
checker-framework copied to clipboard

awt package not annotated

Open shivanshsoni opened this issue 9 years ago • 17 comments

In the following code:

import javax.swing.* ; import java.awt.* ; import java.awt.event.* ; class cardTest implements ActionListener { JFrame fr; JPanel pnl1;

	JButton b1,b2,b3,b4;

	Icon ic1,ic2,ic3,ic4;

	CardLayout card;		
	cardTest()
	{
		ic1=new ImageIcon("img3.jpg");
		ic2=new ImageIcon("img4.jpg");
		ic3=new ImageIcon("img2.png");
		ic4=new ImageIcon("img1.jpg");
		fr=new JFrame("Menu Test");
		pnl1=new JPanel();
		fr.add(pnl1);
		
		b3=new JButton(ic3);
		b4=new JButton(ic4);
		b1=new JButton(ic1);
		b2=new JButton(ic2);

		card=new CardLayout();

		pnl1.setLayout(card);

		pnl1.add(b1);
		b1.addActionListener(this);
		pnl1.add(b2);
		b2.addActionListener(this);

		pnl1.add(b3);
		b3.addActionListener(this);
		pnl1.add(b4);
		b4.addActionListener(this);
		
		fr.setSize(500,500);
		fr.setVisible(true);



	}
	public void actionPerformed(ActionEvent ed)
	{
		card.next(pnl1);
	}
	public static void main(String []args)
	{
		new cardTest();
	}

}

If we compile this code with command javac cardTest.java It will work properly

But by using javac -processor NullnessChecker cardTest.java It is showing error in ActionListener(this) It is not getting (this)

output:

screenshot 26

shivanshsoni avatar Mar 26 '17 04:03 shivanshsoni

The code you pasted in does not compile. Your bug report needs to be more specific than "It is not getting (this)."

mernst avatar Mar 26 '17 05:03 mernst

I think it compiles properly. Please check once again @mernst

shivanshsoni avatar Mar 26 '17 05:03 shivanshsoni

In ActionListener(this) this keyword is not working

shivanshsoni avatar Mar 26 '17 05:03 shivanshsoni

The addActionListener method takes the current class object as a parameter. The "this" keyword simply means "this object I'm working in right now"

shivanshsoni avatar Mar 26 '17 05:03 shivanshsoni

I hope now I defined it properly. @mernst

shivanshsoni avatar Mar 26 '17 05:03 shivanshsoni

What do you mean by "this keyword is not working"? A bug report should say what happened, and also what you expected to happen (and why).

mernst avatar Mar 26 '17 05:03 mernst

this referes to the current instance of object.

say your class A implements the ActionListener. then from your class if you add the listener then you can use this , as for inheritance rule your class is also a listener.

class A implements ActionListener{ Button b; A(){ b1 = new Button(); b1.addActionListener(this); } } Here this is used because the currentobject is also a action listener

shivanshsoni avatar Mar 26 '17 05:03 shivanshsoni

How is this related to the error message that was issued by the checker?

mernst avatar Mar 26 '17 05:03 mernst

Sir actually i mean to say that it is not getting this keyword.. i.e. this keyword is not working in this code

shivanshsoni avatar Mar 26 '17 05:03 shivanshsoni

The errors are related to the Initialization Checker: https://checkerframework.org/manual/#initialization-checker

The Checker Framework doesn't come with annotations for addActionListener so at the moment we require a fully initialized object. In your example, you pass this during construction to this method. You should think whether addActionListener is specified to accept partially initialized objects as argument. If so, we can update the specification for that method.

wmdietl avatar Mar 26 '17 05:03 wmdietl

okk

shivanshsoni avatar Mar 26 '17 06:03 shivanshsoni

I think adding annotation for actionListener would be a good idea

shivanshsoni avatar Mar 26 '17 06:03 shivanshsoni

I've marked this as low priority because the AWT package is deprecated and annotating the whole thing seems like a lot of work. It would definitely improve the Checker Framework, though, and we would welcome a contribution of the annotations.

mernst avatar Mar 27 '17 16:03 mernst

Sir I think we have to improve this issue as most of the users use checker framework for checking large software source codes and i think if we improve this we will surely make it mote successful and it definately improve this.

shivanshsoni avatar Mar 28 '17 07:03 shivanshsoni

If you want i can take this issue as my gsoc project

shivanshsoni avatar Mar 28 '17 07:03 shivanshsoni

That would be fine.

mernst avatar Mar 28 '17 12:03 mernst

Ok Sir Then I am making a new project proposal on this project

shivanshsoni avatar Mar 28 '17 13:03 shivanshsoni