1
00:00:00,670 --> 00:00:05,320
The very last step is to bulletproof the application, in other words, to make sure the application

2
00:00:05,320 --> 00:00:10,540
doesn't fail or crash no matter what happens right now, there are many scenarios where an unchecked

3
00:00:10,540 --> 00:00:14,050
exception could be thrown during the run time and crash the application.

4
00:00:14,260 --> 00:00:15,760
We can't allow that to happen.

5
00:00:16,930 --> 00:00:17,980
So let's run the up.

6
00:00:20,310 --> 00:00:23,910
The first vulnerability in the app is if the user enters a blank movie name.

7
00:00:29,530 --> 00:00:34,330
The movie constructor is going to throw an illegal argument exception, and as you know by now, if

8
00:00:34,330 --> 00:00:37,440
we get an unchecked exception, it's our fault and we have to fix it.

9
00:00:37,900 --> 00:00:42,400
And what we're missing is code that anticipates a scenario where the user may enter a blank name.

10
00:00:42,940 --> 00:00:45,550
So here will say if name is blank.

11
00:00:48,300 --> 00:00:50,160
Then we'll print the following message.

12
00:00:59,240 --> 00:01:01,160
Then we'll restart the loop with continue.

13
00:01:04,900 --> 00:01:06,160
OK, let's run our code.

14
00:01:10,010 --> 00:01:14,690
And if we had a blank name, our application handles the response with grace.

15
00:01:19,850 --> 00:01:21,500
You know what, if I rent a movie?

16
00:01:29,230 --> 00:01:31,120
Then I'll try to purchase that same movie.

17
00:01:36,430 --> 00:01:42,580
And the Atheros, an illegal state exception, crashing the app, we cannot allow the user to purchase

18
00:01:42,580 --> 00:01:44,140
a movie that has already been rented.

19
00:01:44,710 --> 00:01:46,120
So I'll go back in main.

20
00:01:49,480 --> 00:01:51,910
And I'm going to check if the movie is rented.

21
00:01:55,100 --> 00:01:56,380
Wait, how do I do that?

22
00:01:57,590 --> 00:02:03,110
Right now, we can't we need to declare a method inside Staudt Java that returns a movie based on a

23
00:02:03,110 --> 00:02:03,470
name.

24
00:02:11,390 --> 00:02:14,300
So public movie get movie.

25
00:02:17,600 --> 00:02:19,580
It's going to take one parameter string name.

26
00:02:22,620 --> 00:02:25,950
I'm going to create a loop that runs through the size of the array list.

27
00:02:32,030 --> 00:02:33,770
And will say if movies.

28
00:02:38,680 --> 00:02:40,960
We'll get the movie at the request index.

29
00:02:43,130 --> 00:02:47,220
doGet name will check if it equals the name being Pastan.

30
00:02:49,530 --> 00:02:52,530
Then we're going to return the movie object at that inducts.

31
00:03:10,110 --> 00:03:12,150
Otherwise, we're going to return now.

32
00:03:12,880 --> 00:03:18,870
Now, back in Maine, I can get the movie the user is interested in iStore get movie.

33
00:03:24,560 --> 00:03:26,380
We need to check if it's not available.

34
00:03:33,280 --> 00:03:36,130
And if that's the case, will print the following message.

35
00:03:45,540 --> 00:03:48,870
Movie is not available for purchase and restart the while loop.

36
00:03:52,190 --> 00:03:53,560
OK, let's test this out.

37
00:04:00,390 --> 00:04:01,650
I'm going to rent a movie.

38
00:04:10,380 --> 00:04:12,210
Try to purchase that same movie.

39
00:04:16,310 --> 00:04:20,450
And the application responds with Grace, it's not available for purchase.

40
00:04:21,510 --> 00:04:25,380
Now, I'm going to try to purchase another movie, but I'm going to type a movie that isn't on their.

41
00:04:28,220 --> 00:04:29,390
We'll say Django.

42
00:04:30,980 --> 00:04:33,050
And it crashes null pointer exception.

43
00:04:38,700 --> 00:04:43,500
The issue is that the function we just added returns and null if it can't find the movie.

44
00:04:45,420 --> 00:04:50,050
And trying to dot syntax from a nul is going to result in a null pointer exception.

45
00:04:50,550 --> 00:04:52,100
So we need to handle that as well.

46
00:04:55,580 --> 00:05:01,250
So here, instead of checking if the name is blank, I can just make the condition check if the movie

47
00:05:01,250 --> 00:05:02,690
they added doesn't exist.

48
00:05:06,350 --> 00:05:08,660
This condition would account for everything.

49
00:05:11,050 --> 00:05:12,370
Kate running the app.

50
00:05:16,080 --> 00:05:19,650
I'll put a movie that doesn't exist in the collection, we're a good.

51
00:05:20,960 --> 00:05:23,380
I'm going to put a blank movie, we're good.

52
00:05:23,450 --> 00:05:25,090
Our condition is perfect.

53
00:05:26,080 --> 00:05:31,090
And with this final line of code, I'm proud to say that we're all finished no matter what we do, the

54
00:05:31,090 --> 00:05:36,510
application is going to respond with Grace and it's working really well, just like that.

55
00:05:36,520 --> 00:05:38,050
Our application is bulletproof.

56
00:05:39,230 --> 00:05:44,780
No matter what the user throws at us, the application is free of bugs and it's never going to crash.

57
00:05:45,980 --> 00:05:49,100
It can process any input and respond with grace.

58
00:05:51,630 --> 00:05:56,800
In the end, exception handling, which involves catching checked exceptions and fixing unchecked exceptions,

59
00:05:56,800 --> 00:05:59,470
is the key to building bulletproof applications.

