/* Test requires visual inspection of object code to verify */ int noThrow(Main nonNullA,
Main nonNullB,
Main nonNullC) {
// "this" check should be eliminated on both IGET/IPUT
ifoo++;
// "this" check should be eliminated on both IGET/IPUT if (ifoo != 321) { // Check not eliminated
nonNullA.ifoo = 12; // Check not eliminated
nonNullB.ifoo = 21;
} else { // Check not eliminated
nonNullA.ifoo = 12;
}
/* Test to ensure we don't remove necessary null checks */ int checkThrow(Main nonNullA,
Main nonNullB,
Main nonNullC,
Main nullA,
Main nullB,
Main nullC) {
// "this" check should be eliminated on both IGET/IPUT
ifoo++;
try {
nullA.ifoo = 12; // Should not be reached return -1;
} catch (NullPointerException npe) {
ifoo++;
} try {
nullB.ifoo = 13; // Should not be reached return -2;
} catch (NullPointerException npe) {
ifoo++;
} try {
nullC.ifoo = 14; // Should not be reached return -3;
} catch (NullPointerException npe) {
ifoo++;
}
// "this" check should be eliminated if (ifoo != 321) { // Check not eliminated
nonNullA.ifoo = 12; // Check not eliminated
nonNullB.ifoo = 21; // Should throw here try {
nullA.ifoo = 11; return -4;
} catch (NullPointerException npe) {
}
} else { // Check not eliminated
nonNullA.ifoo = 12; // Should throw here try {
nullA.ifoo = 11; return -5;
} catch (NullPointerException npe) {
}
}
// Check not eliminated
nonNullA.ifoo = 13;
// Check not eliminated
nonNullB.ifoo = 21;
nonNullC = nonNullB;
// Check eliminated
nonNullC.ifoo = 32;
// Should throw here try {
nullA.ifoo = 13; return -6;
} catch (NullPointerException npe) {
}
staticint nullCheckTestNoThrow(int x) {
Main base = new Main();
Main a = new Main();
Main b = new Main();
Main c = new Main();
base.ifoo = x; return base.noThrow(a,b,c);
}
staticint nullCheckTestThrow(int x) {
Main base = new Main();
Main a = new Main();
Main b = new Main();
Main c = new Main();
Main d = null;
Main e = null;
Main f = null;
base.ifoo = x; return base.checkThrow(a,b,c,d,e,f);
}
staticvoid throwImplicitAIOBE(int[] array, int index) {
array[index] = 0;
}
staticint checkAIOBE() { int[] array = newint[10]; int res; try {
throwImplicitAIOBE(array, 11);
res = 123;
} catch (NullPointerException npe) {
res = 768;
} catch (ArrayIndexOutOfBoundsException e) {
res = 456;
} try {
throwImplicitAIOBE(array, -1);
res += 123;
} catch (NullPointerException npe) {
res += 768;
} catch (ArrayIndexOutOfBoundsException e) {
res += 456;
} return res;
}
staticint throwImplicitDivZero(int x, int y) { return x / y;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.