| 1 |
// Test case for issue #1214: |
| 2 |
// https://github.com/typetools/checker-framework/issues/1214 |
| 3 |
|
| 4 |
public class Issue1214 { |
| 5 |
static String ng1() { |
| 6 |
String s = "not null"; |
| 7 |
try { |
| 8 |
int data = 50 / 0; |
| 9 |
} catch (Exception e) { |
| 10 |
s = null; |
| 11 |
} |
| 12 |
// :: error: (return.type.incompatible) |
| 13 |
return s; |
| 14 |
} |
| 15 |
|
| 16 |
static String ng2(int x) { |
| 17 |
String s = "not null"; |
| 18 |
try { |
| 19 |
short data = (short) (50 / x); |
| 20 |
} catch (Exception e) { |
| 21 |
try { |
| 22 |
s = null; |
| 23 |
} catch (Exception ee) { |
| 24 |
} |
| 25 |
} |
| 26 |
// :: error: (return.type.incompatible) |
| 27 |
return s; |
| 28 |
} |
| 29 |
|
| 30 |
static String ng3() { |
| 31 |
String s = "not null"; |
| 32 |
try { |
| 33 |
int data = 50 % 0; |
| 34 |
} catch (Exception e) { |
| 35 |
try { |
| 36 |
// some statements... |
| 37 |
} catch (Exception ee) { |
| 38 |
} finally { |
| 39 |
s = null; |
| 40 |
} |
| 41 |
} |
| 42 |
// :: error: (return.type.incompatible) |
| 43 |
return s; |
| 44 |
} |
| 45 |
|
| 46 |
static String ng4(int data) { |
| 47 |
String s = "not null"; |
| 48 |
try { |
| 49 |
data /= 0; |
| 50 |
} catch (Exception e) { |
| 51 |
s = null; |
| 52 |
} |
| 53 |
// :: error: (return.type.incompatible) |
| 54 |
return s; |
| 55 |
} |
| 56 |
|
| 57 |
static String ng5(short data) { |
| 58 |
String s = "not null"; |
| 59 |
try { |
| 60 |
data /= 0; |
| 61 |
} catch (Exception e) { |
| 62 |
try { |
| 63 |
s = null; |
| 64 |
} catch (Exception ee) { |
| 65 |
} |
| 66 |
} |
| 67 |
// :: error: (return.type.incompatible) |
| 68 |
return s; |
| 69 |
} |
| 70 |
|
| 71 |
static String ng6(int data) { |
| 72 |
String s = "not null"; |
| 73 |
try { |
| 74 |
data %= 0; |
| 75 |
} catch (Exception e) { |
| 76 |
try { |
| 77 |
// some statements... |
| 78 |
} catch (Exception ee) { |
| 79 |
} finally { |
| 80 |
s = null; |
| 81 |
} |
| 82 |
} |
| 83 |
// :: error: (return.type.incompatible) |
| 84 |
return s; |
| 85 |
} |
| 86 |
|
| 87 |
static String ok1() { |
| 88 |
String s = "not null"; |
| 89 |
try { |
| 90 |
double data = 50 / 0.0; |
| 91 |
} catch (Exception e) { |
| 92 |
s = null; |
| 93 |
} |
| 94 |
return s; |
| 95 |
} |
| 96 |
|
| 97 |
static String ok2() { |
| 98 |
String s = "not null"; |
| 99 |
try { |
| 100 |
double data = 50 % 0.0; |
| 101 |
} catch (Exception e) { |
| 102 |
s = null; |
| 103 |
} |
| 104 |
return s; |
| 105 |
} |
| 106 |
|
| 107 |
static String ok3(double data) { |
| 108 |
String s = "not null"; |
| 109 |
try { |
| 110 |
data /= 0; |
| 111 |
} catch (Exception e) { |
| 112 |
s = null; |
| 113 |
} |
| 114 |
return s; |
| 115 |
} |
| 116 |
|
| 117 |
static String ok4(float data) { |
| 118 |
String s = "not null"; |
| 119 |
try { |
| 120 |
data %= 0; |
| 121 |
} catch (Exception e) { |
| 122 |
s = null; |
| 123 |
} |
| 124 |
return s; |
| 125 |
} |
| 126 |
} |