-5

I am working on project where I am trying to find programs which give any exception but because of close values. Let me explain by an example. I will highly appreciate any help and support. In the following program first fault is generated when x == 100 and second when x == 98. Cheers.

public class Fault {

    public void faulty(int x, int y) {

        int z;
        y = 20;
        int a [] = new int[10];

        if (x == 100)
        {
            a[11] = 22;
        }

        if ( x == 98)
            z= ( x + y )/0;
    }
}  
MicSim
  • 26,265
  • 16
  • 90
  • 133
Dr. Mian
  • 3,334
  • 10
  • 45
  • 69
  • The question is not clear. If this is a request for "such programs" then I'm not sure this is the place for that. – MByD Aug 09 '11 at 15:22
  • What do you want to know? Do you want to do static code analysis which reveals possible error paths in your application and discover similar error paths depending on variable state? – MicSim Aug 09 '11 at 15:25
  • @Asbat: You must update your question and provide more details. No one here does understand your problem... – home Aug 09 '11 at 15:42
  • You mean like `Object o = null; if (x == 96) o.toString();`? – devconsole Aug 09 '11 at 16:14

1 Answers1

3

The second is obvious:

if ( x == 98)
    z= ( x + y )/0;

Only Jon Skeet can divide by zero.

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • 1
    +1 "Only Jon Skeet can divide by zero." Classic :) – fireshadow52 Aug 09 '11 at 15:26
  • I know the faults in the above programs but I want to write few more examples where the exceptions are caused by close range values for other types like byte, char, long, String etc. – Dr. Mian Aug 09 '11 at 15:28