Constant Conditions & Exceptions  

 

���� ������ �ϳ��� ����(���� ���, ���� �� �Ǵ� ���� ����)�� ������ � ���°� �ִٸ�, �Ǵ� �� ������ ���ܸ� ���������� ���� �� �ִ� �޼ҵ� �κ����̼��� �ִٸ�,  Constant conditions & Exceptions�� �׻� ��ſ��� �˸��� ���� �����εǾ����ϴ�.

���� Constant conditions & exceptions  üũ �ڽ��� ���õǰ� Inspection�� � ������ �߰��ϸ�, Inspection  �� ������� ������ ���� �Ǵ� ���ܸ� ���� �� �ִ� �޼ҵ带 �����ִ� Constant conditions & exceptions  ï¿½ï¿½ï¿½ï¿½ ǥ���մϴ�

�� �˻翡 ���� �߰ߵ� ������ ���� � ���� ������ �ַ�ǵ� �����ϴ�


�� �˻�� � �ɼǵ� ������ �ʽ��ϴ�.


 

��� �������� ����


������ Ŭ������ ���ʽÿ�:

 
  public class MyKeyListener extends KeyAdapter {
    public void keyTyped(KeyEvent e) {
      int keyCode = e.getKeyCode();
 
      if (keyCode == KeyEvent.VK_F1) {
        showHelp();
      }
      else if (keyCode == KeyEvent.VK_F2) {
        saveCurrentFile();
      }
      else if (keyCode == KeyEvent.VK_F1) { // Error here. Should be KeyEvent.VK_F3
        openNewFile();
      }
      else if (keyCode == KeyEvent.VK_F4) {
        closeCurrentFile();
      }
    }


Inspection 
����� �� �����쿡 ��Ÿ���ϴ�:



�˻�� ���� <else if (keyCode == KeyEvent.VK_F1)> �� �׻� false �̰� �׷��Ƿ� �װ��� ���� ������� ���� ���̶�� ���� �츮���� �˸��ϴ�.

��� ��- NPE ����


���� ���, ������ �ڵ带 �����Ͻʽÿ�:

 
    public void myMethod(String m_str) {
        String str = m_str;
        if (str != null) {
            System.out.println(str.charAt(1));
        }
 
        ...
 
        //some code here - but str is not changed
 
        ...
 
        System.out.println(str.charAt(1));
    }


Inspection 
����� �� �����쿡 ��Ÿ���ϴ�:



�� �˻�� NPE�� ���ڿ� <�� ��������� �𸣴� ���� �츮���� �˸��ϴ� ><System.out.println(str.charAt(1));> ���� �����Ǿ��� ���� �츮���� �˷��ݴϴ�.

�׷���, if ���� ���� �� �޼ҵ�� ���õ� �� �Դϴ�(�翬��, IDEA�� ��� ���� �Ű� �����μ� �޼ҵ忡 �Ѿ���� �𸨴ϴ�).