-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathTest.java
More file actions
136 lines (117 loc) · 4.21 KB
/
Copy pathTest.java
File metadata and controls
136 lines (117 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import java.io.*;
public class Test {
public static void main(String[] args) {
test1();
test2();
test3();
}
static void test1() {
Byte.parseByte("123"); // $ Alert
Byte.decode("123"); // $ Alert
Byte.valueOf("123"); // $ Alert
Byte.valueOf("123", 10); // $ Alert
Byte.valueOf("7f", 16); // $ Alert
new Byte("123"); // $ Alert
new Byte((byte) 123); // don't flag: wrong constructor
Short.parseShort("123"); // $ Alert
Short.decode("123"); // $ Alert
Short.valueOf("123"); // $ Alert
Short.valueOf("123", 10); // $ Alert
Short.valueOf("7abc", 16); // $ Alert
new Short("123"); // $ Alert
new Short((short) 123); // don't flag: wrong constructor
Integer.parseInt("123"); // $ Alert
Integer.decode("123"); // $ Alert
Integer.valueOf("123"); // $ Alert
Integer.valueOf("123", 10); // $ Alert
Integer.valueOf("1234beef", 16); // $ Alert
new Integer("123"); // $ Alert
new Integer(123); // don't flag: wrong constructor
Long.parseLong("123"); // $ Alert
Long.decode("123"); // $ Alert
Long.valueOf("123"); // $ Alert
Long.valueOf("123", 10); // $ Alert
Long.valueOf("deadbeef", 16); // $ Alert
new Long("123"); // $ Alert
new Long(123l); // don't flag: wrong constructor
Float.parseFloat("2.7818281828"); // $ Alert
Float.valueOf("2.7818281828"); // $ Alert
new Float("2.7818281828"); // $ Alert
new Float(2.7818281828f); // don't flag: wrong constructor
Double.parseDouble("2.7818281828"); // $ Alert
Double.valueOf("2.7818281828"); // $ Alert
new Double("2.7818281828"); // $ Alert
new Double(2.7818281828); // don't flag: wrong constructor
}
static void test2() {
// Don't flag any of these. The exception is caught.
try {
Byte.parseByte("123");
Byte.decode("123");
Byte.valueOf("123");
Byte.valueOf("123", 10);
Byte.valueOf("7f", 16);
new Byte("123");
Short.parseShort("123");
Short.decode("123");
Short.valueOf("123");
Short.valueOf("123", 10);
Short.valueOf("7abc", 16);
new Short("123");
Integer.parseInt("123");
Integer.decode("123");
Integer.valueOf("123");
Integer.valueOf("123", 10);
Integer.valueOf("1234beef", 16);
new Integer("123");
Long.parseLong("123");
Long.decode("123");
Long.valueOf("123");
Long.valueOf("123", 10);
Long.valueOf("deadbeef", 16);
new Long("123");
Float.parseFloat("2.7818281828");
Float.valueOf("2.7818281828");
new Float("2.7818281828");
Double.parseDouble("2.7818281828");
Double.valueOf("2.7818281828");
new Double("2.7818281828");
}
catch (NumberFormatException e) {
// parse error
}
}
static void test3() throws NumberFormatException {
// Don't flag any of these: the exception is explcitly declared
Byte.parseByte("123");
Byte.decode("123");
Byte.valueOf("123");
Byte.valueOf("123", 10);
Byte.valueOf("7f", 16);
new Byte("123");
Short.parseShort("123");
Short.decode("123");
Short.valueOf("123");
Short.valueOf("123", 10);
Short.valueOf("7abc", 16);
new Short("123");
Integer.parseInt("123");
Integer.decode("123");
Integer.valueOf("123");
Integer.valueOf("123", 10);
Integer.valueOf("1234beef", 16);
new Integer("123");
Long.parseLong("123");
Long.decode("123");
Long.valueOf("123");
Long.valueOf("123", 10);
Long.valueOf("deadbeef", 16);
new Long("123");
Float.parseFloat("2.7818281828");
Float.valueOf("2.7818281828");
new Float("2.7818281828");
Double.parseDouble("2.7818281828");
Double.valueOf("2.7818281828");
new Double("2.7818281828");
}
}