Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS_OPEN_STREAM #42

Open
marcoym2 opened this issue Aug 16, 2023 · 0 comments
Open

OS_OPEN_STREAM #42

marcoym2 opened this issue Aug 16, 2023 · 0 comments

Comments

@marcoym2
Copy link

marcoym2 commented Aug 16, 2023

report name: OS_OPEN_STREAM

To reproduce:
Eclipse development env:
SpotBugs
Expected Behavior:
the file open the stream and without a close stream, which will make the application memory leaking and crash

    try
    {           
    File f = new File("backup");
    if(f.exists())
    {
        FileInputStream fin=new FileInputStream(f);
        ObjectInputStream ois=new ObjectInputStream(fin);
        Hotel.hotel_ob=(holder)ois.readObject();
    }
    Scanner sc = new Scanner(System.in);
    int ch,ch2;
    char wish;
    x:
    do{

    System.out.println("\nEnter your choice :\n1.Display room details\n2.Display room availability \n3.Book\n4.Order food\n5.Checkout\n6.Exit\n");
    ch = sc.nextInt();
    switch(ch){
        case 1: System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room \n4.Deluxe Single Room\n");
                ch2 = sc.nextInt();
                Hotel.features(ch2);
            break;
        case 2:System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n");
                 ch2 = sc.nextInt();
                 Hotel.availability(ch2);
            break;
        case 3:System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n");
                 ch2 = sc.nextInt();
                 Hotel.bookroom(ch2);                     
            break;
        case 4:
             System.out.print("Room Number -");
                 ch2 = sc.nextInt();
                 if(ch2>60)
                     System.out.println("Room doesn't exist");
                 else if(ch2>40)
                     Hotel.order(ch2-41,4);
                 else if(ch2>30)
                     Hotel.order(ch2-31,3);
                 else if(ch2>10)
                     Hotel.order(ch2-11,2);
                 else if(ch2>0)
                     Hotel.order(ch2-1,1);
                 else
                     System.out.println("Room doesn't exist");
                 break;
        case 5:                 
            System.out.print("Room Number -");
                 ch2 = sc.nextInt();
                 if(ch2>60)
                     System.out.println("Room doesn't exist");
                 else if(ch2>40)
                     Hotel.deallocate(ch2-41,4);
                 else if(ch2>30)
                     Hotel.deallocate(ch2-31,3);
                 else if(ch2>10)
                     Hotel.deallocate(ch2-11,2);
                 else if(ch2>0)
                     Hotel.deallocate(ch2-1,1);
                 else
                     System.out.println("Room doesn't exist");
                 break;
        case 6:break x;
            
    }
       
        System.out.println("\nContinue : (y/n)");
        wish=sc.next().charAt(0); 
        if(!(wish=='y'||wish=='Y'||wish=='n'||wish=='N'))
        {
            System.out.println("Invalid Option");
            System.out.println("\nContinue : (y/n)");
            wish=sc.next().charAt(0); 
        }
        
    }while(wish=='y'||wish=='Y');    
    
    Thread t=new Thread(new write(Hotel.hotel_ob));
    t.start();
    }        
        catch(Exception e)
        {
            System.out.println("Not a valid input");
        }
}

}

enviorment:
eclipse env:
Possible solution: should close the file stream without making the application crash
Impact: high
Severity: high

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant