Community
Participate
Working Groups
Build id: M20080911-1700 On the attached java file, there one final local which is marked as "Potential null pointer access". The odd thing is that it is only showed on the second block of code, not on the first one. The 2 blocks are almost identical so it looks like a bug.
Created attachment 113717 [details] The java file which show the weird warning You can uncomment the second block of code to test the behaviour
This is because of the first "mi.setEnabled(n != null);". The null analysis of the actionListeners should not use the outer code between them; but i'm no JLS expert.
final N n = n_; // 1 mi = new JMenuItem(L._("T1")); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String titre = JOptionPane.showInputDialog(parent, L._("Text1") + " :"); if (titre != null && titre.length() > 0) getModele().i(N.titre(titre), n, n.get5()); // 4 } }); mi.setEnabled(n != null); // 2 popup.add(mi); // +++ mi = new JMenuItem(L._("T2")); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String texte = JOptionPane.showInputDialog(parent, L._("Text2") + " :"); if (texte != null && texte.length() > 0) getModele().i(N.t1(texte), n, n.get5()); // 3 } }); This is not really a bug. On line commented as 1, the compiler marks n as assigned to an unknown value ( it could be either null , or non null depending on runtime). When the user checks n against null in line commented as 2, the compiler considers it as tainted, and marks it maybe null. This is the reason for the potential null warning on line commented as 3. Although the same kind of call was done on line commented as 4, no warning was given here as until here the variable 'n' hadn't been tainted by the user. Change line 1 and initialise n using a constructor, and the warning goes away - because now the compiler is sure that we started out with n as surely non null. This is just a conservative way of flagging potential null references, and is OK IMO.
I intend to close the bug as invalid. If i'm missing something here, please point it out. Thanks.
Closing as INVALID.
Verified for 3.6M5 using I20100125-0800