1 package soot.toolkits.exceptions; 2 3 import soot.*; 4 import soot.toolkits.scalar.*; 5 import soot.jimple.*; 6 import soot.jimple.internal.*; 7 import soot.grimp.*; 8 import soot.grimp.internal.*; 9 import soot.toolkits.exceptions.*; 10 import java.util.*; 11 import junit.framework.Test; 12 import junit.framework.TestCase; 13 import junit.framework.TestSuite; 14 import soot.toolkits.exceptions.ExceptionTestUtility; 15 import soot.toolkits.exceptions.ExceptionTestUtility.ExceptionHashSet; 16 17 public class UnitThrowAnalysisTest extends TestCase { 18 19 class ImmaculateInvokeUnitThrowAnalysis extends UnitThrowAnalysis { 20 26 ThrowableSet mightThrow(SootMethod m) { 27 return ThrowableSet.Manager.v().EMPTY; 28 } 29 } 30 31 UnitThrowAnalysis unitAnalysis; 32 UnitThrowAnalysis immaculateAnalysis; 33 34 protected StaticFieldRef floatStaticFieldRef; 36 protected Local floatLocal; 37 protected FloatConstant floatConstant; 38 protected Local floatConstantLocal; 39 protected InstanceFieldRef floatInstanceFieldRef; 40 protected ArrayRef floatArrayRef; 41 protected VirtualInvokeExpr floatVirtualInvoke; 42 protected StaticInvokeExpr floatStaticInvoke; 43 44 private static String jdkLocation = "/usr/localcc/pkgs/jdk1.4/jre/lib/rt.jar"; 46 47 private ExceptionTestUtility utility; 48 49 public UnitThrowAnalysisTest(String name) { 50 super(name); 51 unitAnalysis = new UnitThrowAnalysis(); 52 immaculateAnalysis = new ImmaculateInvokeUnitThrowAnalysis(); 53 } 54 55 protected void setUp() { 56 utility = new ExceptionTestUtility(jdkLocation); 58 59 SootClass bogusClass = new SootClass("BogusClass"); 60 SootFieldRef nanFieldRef = Scene.v().makeFieldRef(Scene.v().getSootClass("java.lang.Float"), 61 "NaN", FloatType.v(), 62 true); 63 floatStaticFieldRef = Grimp.v().newStaticFieldRef(nanFieldRef); 64 floatLocal = Grimp.v().newLocal("local", FloatType.v()); 65 floatConstant = FloatConstant.v(33.42f); 66 floatConstantLocal = Grimp.v().newLocal("local", RefType.v("soot.jimple.FloatConstant")); 67 SootFieldRef valueFieldRef 68 = Scene.v().makeFieldRef(bogusClass, "value", FloatType.v(), false); 69 floatInstanceFieldRef = Grimp.v().newInstanceFieldRef(floatConstantLocal, 70 valueFieldRef); 71 floatArrayRef = Grimp.v().newArrayRef( 72 Jimple.v().newLocal("local1", FloatType.v()), 73 IntConstant.v(0)); 74 List voidList = new ArrayList(); 75 floatVirtualInvoke = Grimp.v().newVirtualInvokeExpr( 76 floatConstantLocal, 77 Scene.v().makeMethodRef(bogusClass, "floatFunction", voidList, 78 FloatType.v(), false), 79 voidList); 80 floatStaticInvoke = Grimp.v().newStaticInvokeExpr( 81 Scene.v().makeMethodRef(bogusClass, "floatFunction", 82 Arrays.asList(new Type[] { 83 FloatType.v(), FloatType.v(),}), 84 FloatType.v(), true), 85 Arrays.asList(new Value[] { 86 floatStaticFieldRef, floatArrayRef,}) 87 ); 88 } 89 90 91 public void testJBreakpointStmt() { 92 Stmt s = Grimp.v().newBreakpointStmt(); 93 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 94 unitAnalysis.mightThrow(s))); 95 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 96 utility.catchableSubset(unitAnalysis.mightThrow(s))); 97 } 98 99 public void testGBreakpointStmt() { 100 Stmt s = Grimp.v().newBreakpointStmt(); 101 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 102 unitAnalysis.mightThrow(s))); 103 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 104 utility.catchableSubset(unitAnalysis.mightThrow(s))); 105 } 106 107 public void testJInvokeStmt() { 108 List voidList = new ArrayList(); 109 Stmt s = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr( 110 Jimple.v().newLocal("local1", RefType.v("java.lang.Object")), 111 Scene.v().makeMethodRef(Scene.v().getSootClass("java.lang.Object"), 112 "wait", voidList, VoidType.v(), false), 113 voidList)); 114 ExceptionHashSet expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_METHOD_ERRORS_REP); 115 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 116 ExceptionHashSet expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_METHOD_ERRORS_PLUS_SUPERTYPES); 117 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 118 expectedCatch.add(utility.RUNTIME_EXCEPTION); 119 expectedCatch.add(utility.EXCEPTION); 120 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 121 immaculateAnalysis.mightThrow(s))); 122 assertEquals(expectedCatch, 123 utility.catchableSubset(immaculateAnalysis.mightThrow(s))); 124 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 125 Collections.EMPTY_SET, 126 unitAnalysis.mightThrow(s))); 127 assertEquals(utility.ALL_TEST_THROWABLES, 128 utility.catchableSubset(unitAnalysis.mightThrow(s))); 129 130 s = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr( 131 Scene.v().makeMethodRef(new SootClass("BogusClass"), "no.such.method", 132 voidList, VoidType.v(), false), 133 voidList)); 134 assertTrue(utility.sameMembers(utility.ALL_ERRORS_REP, 135 Collections.EMPTY_SET, 136 immaculateAnalysis.mightThrow(s))); 137 assertEquals(utility.ALL_TEST_ERRORS_PLUS_SUPERTYPES, 138 utility.catchableSubset(immaculateAnalysis.mightThrow(s))); 139 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 140 Collections.EMPTY_SET, 141 unitAnalysis.mightThrow(s))); 142 assertEquals(utility.ALL_TEST_THROWABLES, 143 utility.catchableSubset(unitAnalysis.mightThrow(s))); 144 } 145 146 public void testGInvokeStmt() { 147 List voidList = new ArrayList(); 148 Stmt s = Grimp.v().newInvokeStmt(Grimp.v().newVirtualInvokeExpr( 149 Grimp.v().newLocal("local1", RefType.v("java.lang.Object")), 150 Scene.v().makeMethodRef(Scene.v().getSootClass("java.lang.Object"), 151 "wait", voidList, VoidType.v(), false), 152 voidList)); 153 ExceptionHashSet expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_METHOD_ERRORS_REP); 154 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 155 ExceptionHashSet expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_METHOD_ERRORS_PLUS_SUPERTYPES); 156 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 157 expectedCatch.add(utility.RUNTIME_EXCEPTION); 158 expectedCatch.add(utility.EXCEPTION); 159 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 160 immaculateAnalysis.mightThrow(s))); 161 assertEquals(expectedCatch, 162 utility.catchableSubset(immaculateAnalysis.mightThrow(s))); 163 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 164 Collections.EMPTY_SET, 165 unitAnalysis.mightThrow(s))); 166 assertEquals(utility.ALL_TEST_THROWABLES, 167 utility.catchableSubset(unitAnalysis.mightThrow(s))); 168 169 s = Grimp.v().newInvokeStmt(Grimp.v().newStaticInvokeExpr( 170 Scene.v().makeMethodRef(new SootClass("BogusClass"), "no.such.method", 171 voidList, VoidType.v(), true), 172 voidList)); 173 assertTrue(utility.sameMembers(utility.ALL_ERRORS_REP, 174 Collections.EMPTY_SET, 175 immaculateAnalysis.mightThrow(s))); 176 assertEquals(utility.ALL_TEST_ERRORS_PLUS_SUPERTYPES, 177 utility.catchableSubset(immaculateAnalysis.mightThrow(s))); 178 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 179 Collections.EMPTY_SET, 180 unitAnalysis.mightThrow(s))); 181 assertEquals(utility.ALL_TEST_THROWABLES, 182 utility.catchableSubset(unitAnalysis.mightThrow(s))); 183 } 184 185 public void testJAssignStmt() { 186 187 Stmt s = Jimple.v().newAssignStmt(Jimple.v().newLocal("local0", 189 IntType.v()), 190 IntConstant.v(0)); 191 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 192 unitAnalysis.mightThrow(s))); 193 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 194 utility.catchableSubset(unitAnalysis.mightThrow(s))); 195 196 ArrayRef arrayRef = Jimple.v().newArrayRef( 197 Jimple.v().newLocal("local1", 198 ArrayType.v(RefType.v("java.lang.Object"), 1)), 199 IntConstant.v(0)); 200 Local scalarRef = Jimple.v().newLocal("local2", 201 RefType.v("java.lang.Object")); 202 203 s = Jimple.v().newAssignStmt(scalarRef, arrayRef); 205 206 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 207 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 208 expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 209 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 210 unitAnalysis.mightThrow(s))); 211 212 Set expectedCatch = 213 new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 214 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 215 expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 216 expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION); 217 expectedCatch.add(utility.RUNTIME_EXCEPTION); 218 expectedCatch.add(utility.EXCEPTION); 219 assertEquals(expectedCatch, 220 utility.catchableSubset(unitAnalysis.mightThrow(s))); 221 222 s = Jimple.v().newAssignStmt(arrayRef, scalarRef); 224 expectedRep.add(utility.ARRAY_STORE_EXCEPTION); 225 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 226 unitAnalysis.mightThrow(s))); 227 expectedCatch.add(utility.ARRAY_STORE_EXCEPTION); 228 assertEquals(expectedCatch, 229 utility.catchableSubset(unitAnalysis.mightThrow(s))); 230 } 231 232 public void testGAssignStmt() { 233 234 Stmt s = Grimp.v().newAssignStmt(Grimp.v().newLocal("local0", 236 IntType.v()), 237 IntConstant.v(0)); 238 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 239 unitAnalysis.mightThrow(s))); 240 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 241 utility.catchableSubset(unitAnalysis.mightThrow(s))); 242 243 ArrayRef arrayRef = Grimp.v().newArrayRef( 244 Grimp.v().newLocal("local1", 245 ArrayType.v(RefType.v("java.lang.Object"), 1)), 246 IntConstant.v(0)); 247 Local scalarRef = Grimp.v().newLocal("local2", 248 RefType.v("java.lang.Object")); 249 250 s = Grimp.v().newAssignStmt(scalarRef, arrayRef); 252 253 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 254 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 255 expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 256 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 257 unitAnalysis.mightThrow(s))); 258 Set expectedCatch = 259 new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 260 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 261 expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 262 expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION); 263 expectedCatch.add(utility.RUNTIME_EXCEPTION); 264 expectedCatch.add(utility.EXCEPTION); 265 assertEquals(expectedCatch, 266 utility.catchableSubset(unitAnalysis.mightThrow(s))); 267 268 s = Grimp.v().newAssignStmt(arrayRef, scalarRef); 270 expectedRep.add(utility.ARRAY_STORE_EXCEPTION); 271 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 272 unitAnalysis.mightThrow(s))); 273 expectedCatch.add(utility.ARRAY_STORE_EXCEPTION); 274 assertEquals(expectedCatch, 275 utility.catchableSubset(unitAnalysis.mightThrow(s))); 276 } 277 278 public void testJIdentityStmt() { 279 280 Stmt s = Jimple.v().newIdentityStmt(Grimp.v().newLocal("local0", 281 IntType.v()), 282 Jimple.v().newCaughtExceptionRef()); 283 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 284 unitAnalysis.mightThrow(s))); 285 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 286 utility.catchableSubset(unitAnalysis.mightThrow(s))); 287 288 s = Jimple.v().newIdentityStmt(Grimp.v().newLocal("local0", 289 RefType.v("java.lang.NullPointerException")), 290 Jimple.v().newThisRef(RefType.v("java.lang.NullPointerException"))); 291 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 292 unitAnalysis.mightThrow(s))); 293 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 294 utility.catchableSubset(unitAnalysis.mightThrow(s))); 295 296 s = Jimple.v().newIdentityStmt(Grimp.v().newLocal("local0", 297 RefType.v("java.lang.NullPointerException")), 298 Jimple.v().newParameterRef(RefType.v("java.lang.NullPointerException"), 299 0)); 300 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 301 unitAnalysis.mightThrow(s))); 302 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 303 utility.catchableSubset(unitAnalysis.mightThrow(s))); 304 } 305 306 public void testGIdentityStmt() { 307 308 Stmt s = Grimp.v().newIdentityStmt(Grimp.v().newLocal("local0", 309 IntType.v()), 310 Grimp.v().newCaughtExceptionRef()); 311 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 312 unitAnalysis.mightThrow(s))); 313 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 314 utility.catchableSubset(unitAnalysis.mightThrow(s))); 315 316 s = Grimp.v().newIdentityStmt(Grimp.v().newLocal("local0", 317 RefType.v("java.lang.NullPointerException")), 318 Grimp.v().newThisRef(RefType.v("java.lang.NullPointerException"))); 319 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 320 unitAnalysis.mightThrow(s))); 321 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 322 utility.catchableSubset(unitAnalysis.mightThrow(s))); 323 324 s = Grimp.v().newIdentityStmt(Grimp.v().newLocal("local0", 325 RefType.v("java.lang.NullPointerException")), 326 Grimp.v().newParameterRef(RefType.v("java.lang.NullPointerException"), 327 0)); 328 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 329 unitAnalysis.mightThrow(s))); 330 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 331 utility.catchableSubset(unitAnalysis.mightThrow(s))); 332 } 333 334 public void testJEnterMonitorStmt() { 335 Stmt s = Jimple.v().newEnterMonitorStmt(StringConstant.v("test")); 336 337 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 338 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 339 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 340 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 341 unitAnalysis.mightThrow(s))); 342 343 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 344 expectedCatch.add(utility.RUNTIME_EXCEPTION); 345 expectedCatch.add(utility.EXCEPTION); 346 assertEquals(expectedCatch, 347 utility.catchableSubset(unitAnalysis.mightThrow(s))); 348 } 349 350 public void testGEnterMonitorStmt() { 351 Stmt s = Grimp.v().newEnterMonitorStmt(StringConstant.v("test")); 352 353 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 354 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 355 356 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 357 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 358 unitAnalysis.mightThrow(s))); 359 360 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 361 expectedCatch.add(utility.RUNTIME_EXCEPTION); 362 expectedCatch.add(utility.EXCEPTION); 363 assertEquals(expectedCatch, 364 utility.catchableSubset(unitAnalysis.mightThrow(s))); 365 } 366 367 public void testJExitMonitorStmt() { 368 Stmt s = Jimple.v().newExitMonitorStmt(StringConstant.v("test")); 369 370 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 371 expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 372 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 373 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 374 unitAnalysis.mightThrow(s))); 375 376 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 377 expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 378 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 379 expectedCatch.add(utility.RUNTIME_EXCEPTION); 380 expectedCatch.add(utility.EXCEPTION); 381 assertEquals(expectedCatch, 382 utility.catchableSubset(unitAnalysis.mightThrow(s))); 383 } 384 385 public void testGExitMonitorStmt() { 386 Stmt s = Grimp.v().newExitMonitorStmt(StringConstant.v("test")); 387 388 389 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 390 expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 391 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 392 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 393 unitAnalysis.mightThrow(s))); 394 395 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 396 expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 397 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 398 expectedCatch.add(utility.RUNTIME_EXCEPTION); 399 expectedCatch.add(utility.EXCEPTION); 400 401 assertEquals(expectedCatch, 402 utility.catchableSubset(unitAnalysis.mightThrow(s))); 403 } 404 405 public void testJGotoStmt() { 406 Stmt nop = Jimple.v().newNopStmt(); 407 Stmt s = Jimple.v().newGotoStmt(nop); 408 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 409 unitAnalysis.mightThrow(s))); 410 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 411 utility.catchableSubset(unitAnalysis.mightThrow(s))); 412 } 413 414 public void testGGotoStmt() { 415 Stmt nop = Grimp.v().newNopStmt(); 416 Stmt s = Grimp.v().newGotoStmt(nop); 417 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 418 unitAnalysis.mightThrow(s))); 419 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 420 utility.catchableSubset(unitAnalysis.mightThrow(s))); 421 } 422 423 public void testJIfStmt() { 424 IfStmt s = Jimple.v().newIfStmt(Jimple.v().newEqExpr(IntConstant.v(1), 425 IntConstant.v(1)), 426 (Unit) null); 427 s.setTarget(s); assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 429 unitAnalysis.mightThrow(s))); 430 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 431 utility.catchableSubset(unitAnalysis.mightThrow(s))); 432 } 433 434 public void testGIfStmt() { 435 IfStmt s = Grimp.v().newIfStmt(Grimp.v().newEqExpr(IntConstant.v(1), 436 IntConstant.v(1)), 437 (Unit) null); 438 s.setTarget(s); assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 440 unitAnalysis.mightThrow(s))); 441 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 442 utility.catchableSubset(unitAnalysis.mightThrow(s))); 443 } 444 445 public void testJLookupSwitchStmt() { 446 Stmt target = Jimple.v().newAssignStmt(Jimple.v().newLocal("local0", 447 IntType.v()), 448 IntConstant.v(0)); 449 Stmt s = Jimple.v().newLookupSwitchStmt(IntConstant.v(1), 450 Arrays.asList(new Value[] { 451 IntConstant.v(1) 452 }), 453 Arrays.asList(new Unit[] { 454 target 455 }), 456 target); 457 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 458 unitAnalysis.mightThrow(s))); 459 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 460 utility.catchableSubset(unitAnalysis.mightThrow(s))); 461 } 462 463 public void testGLookupSwitchStmt() { 464 Stmt target = Grimp.v().newAssignStmt(Grimp.v().newLocal("local0", 465 IntType.v()), 466 IntConstant.v(0)); 467 Stmt s = Grimp.v().newLookupSwitchStmt(IntConstant.v(1), 468 Arrays.asList(new Value[] { 469 IntConstant.v(1) 470 }), 471 Arrays.asList(new Unit[] { 472 target 473 }), 474 target); 475 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 476 unitAnalysis.mightThrow(s))); 477 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 478 utility.catchableSubset(unitAnalysis.mightThrow(s))); 479 } 480 481 public void testJNopStmt() { 482 Stmt s = Jimple.v().newNopStmt(); 483 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 484 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 485 unitAnalysis.mightThrow(s))); 486 } 487 488 public void testGNopStmt() { 489 Stmt s = Grimp.v().newNopStmt(); 490 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 491 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 492 unitAnalysis.mightThrow(s))); 493 } 494 495 public void testJReturnStmt() { 496 Stmt s = Jimple.v().newReturnStmt(IntConstant.v(1)); 497 498 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 499 expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 500 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 501 unitAnalysis.mightThrow(s))); 502 503 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 504 expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 505 expectedCatch.add(utility.RUNTIME_EXCEPTION); 506 expectedCatch.add(utility.EXCEPTION); 507 assertEquals(expectedCatch, 508 utility.catchableSubset(unitAnalysis.mightThrow(s))); 509 } 510 511 public void testGReturnStmt() { 512 Stmt s = Grimp.v().newReturnStmt(IntConstant.v(1)); 513 514 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 515 expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 516 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 517 unitAnalysis.mightThrow(s))); 518 519 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 520 expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 521 expectedCatch.add(utility.RUNTIME_EXCEPTION); 522 expectedCatch.add(utility.EXCEPTION); 523 assertEquals(expectedCatch, 524 utility.catchableSubset(unitAnalysis.mightThrow(s))); 525 } 526 527 public void testJReturnVoidStmt() { 528 Stmt s = Jimple.v().newReturnVoidStmt(); 529 530 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 531 expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 532 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 533 unitAnalysis.mightThrow(s))); 534 535 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 536 expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 537 expectedCatch.add(utility.RUNTIME_EXCEPTION); 538 expectedCatch.add(utility.EXCEPTION); 539 assertEquals(expectedCatch, 540 utility.catchableSubset(unitAnalysis.mightThrow(s))); 541 } 542 543 public void testGReturnVoidStmt() { 544 Stmt s = Grimp.v().newReturnVoidStmt(); 545 546 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 547 expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 548 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 549 unitAnalysis.mightThrow(s))); 550 551 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 552 expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION); 553 expectedCatch.add(utility.RUNTIME_EXCEPTION); 554 expectedCatch.add(utility.EXCEPTION); 555 assertEquals(expectedCatch, 556 utility.catchableSubset(unitAnalysis.mightThrow(s))); 557 } 558 559 public void testJTableSwitchStmt() { 560 Stmt target = Jimple.v().newAssignStmt(Jimple.v().newLocal("local0", 561 IntType.v()), 562 IntConstant.v(0)); 563 Stmt s = Jimple.v().newTableSwitchStmt(IntConstant.v(1), 0, 1, 564 Arrays.asList(new Unit[] { 565 target 566 }), 567 target); 568 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 569 unitAnalysis.mightThrow(s))); 570 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 571 utility.catchableSubset(unitAnalysis.mightThrow(s))); 572 } 573 574 public void testGTableSwitchStmt() { 575 Stmt target = Grimp.v().newAssignStmt(Grimp.v().newLocal("local0", 576 IntType.v()), 577 IntConstant.v(0)); 578 Stmt s = Grimp.v().newTableSwitchStmt(IntConstant.v(1), 0, 1, 579 Arrays.asList(new Unit[] { 580 target 581 }), 582 target); 583 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 584 unitAnalysis.mightThrow(s))); 585 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 586 utility.catchableSubset(unitAnalysis.mightThrow(s))); 587 } 588 589 public void testJThrowStmt() { 590 591 ThrowStmt s = Jimple.v().newThrowStmt(Jimple.v().newLocal("local0", 594 RefType.v("java.lang.NullPointerException"))); 595 Set expectedRep = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS); 596 expectedRep.remove(utility.NULL_POINTER_EXCEPTION); 597 expectedRep.add(AnySubType.v(utility.NULL_POINTER_EXCEPTION)); 598 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 599 unitAnalysis.mightThrow(s))); 600 assertEquals(utility.PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES, 601 utility.catchableSubset(unitAnalysis.mightThrow(s))); 602 603 Local local = Jimple.v().newLocal("local1", 605 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 606 s.setOp(local); 607 expectedRep = new ExceptionHashSet(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE); 608 expectedRep.remove(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 609 expectedRep.add(AnySubType.v(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR)); 610 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 611 unitAnalysis.mightThrow(s))); 612 assertEquals(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES_PLUS_SUPERTYPES, 613 utility.catchableSubset(unitAnalysis.mightThrow(s))); 614 615 local = Jimple.v().newLocal("local1", soot.UnknownType.v()); 617 s.setOp(local); 618 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 619 Collections.EMPTY_SET, 620 unitAnalysis.mightThrow(s))); 621 assertEquals(utility.ALL_TEST_THROWABLES, 622 utility.catchableSubset(unitAnalysis.mightThrow(s))); 623 } 624 625 public void testGThrowStmt() { 626 ThrowStmt s = Grimp.v().newThrowStmt(Grimp.v().newLocal("local0", 627 RefType.v("java.util.zip.ZipException"))); 628 629 Set expectedRep = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS); 630 expectedRep.add(AnySubType.v(Scene.v().getRefType("java.util.zip.ZipException"))); 631 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 632 unitAnalysis.mightThrow(s))); 633 634 Set expectedCatch = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES); 635 assertEquals(expectedCatch, 638 utility.catchableSubset(unitAnalysis.mightThrow(s))); 639 640 s = Grimp.v().newThrowStmt( 642 Grimp.v().newNewInvokeExpr( 643 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR, 644 Scene.v().makeMethodRef(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR.getSootClass(), 645 "void <init>", Collections.EMPTY_LIST, 646 VoidType.v(), false), 647 new ArrayList() 648 ) 649 ); 650 assertTrue(utility.sameMembers(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE, 651 Collections.EMPTY_SET, 652 unitAnalysis.mightThrow(s))); 653 assertEquals(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUPERTYPES, 654 utility.catchableSubset(unitAnalysis.mightThrow(s))); 655 656 Local local = Grimp.v().newLocal("local1", 658 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 659 s.setOp(local); 660 expectedRep = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS); 661 expectedRep.remove(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 662 expectedRep.add(AnySubType.v(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR)); 663 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 664 unitAnalysis.mightThrow(s))); 665 assertEquals(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES_PLUS_SUPERTYPES, 666 utility.catchableSubset(unitAnalysis.mightThrow(s))); 667 668 local = Jimple.v().newLocal("local1", soot.UnknownType.v()); 670 s.setOp(local); 671 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 672 Collections.EMPTY_SET, 673 unitAnalysis.mightThrow(s))); 674 assertEquals(utility.ALL_TEST_THROWABLES, 675 utility.catchableSubset(unitAnalysis.mightThrow(s))); 676 } 677 678 679 public void testJArrayRef() { 680 ArrayRef arrayRef = Jimple.v().newArrayRef( 681 Jimple.v().newLocal("local1", 682 ArrayType.v(RefType.v("java.lang.Object"), 1)), 683 IntConstant.v(0)); 684 685 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 686 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 687 expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 688 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 689 unitAnalysis.mightThrow(arrayRef))); 690 691 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 692 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 693 expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 694 expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION); 695 expectedCatch.add(utility.RUNTIME_EXCEPTION); 696 expectedCatch.add(utility.EXCEPTION); 697 assertEquals(expectedCatch, 698 utility.catchableSubset(unitAnalysis.mightThrow(arrayRef))); 699 } 700 701 public void testGArrayRef() { 702 ArrayRef arrayRef = Grimp.v().newArrayRef( 703 Grimp.v().newLocal("local1", 704 ArrayType.v(RefType.v("java.lang.Object"), 1)), 705 IntConstant.v(0)); 706 707 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 708 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 709 expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 710 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 711 unitAnalysis.mightThrow(arrayRef))); 712 713 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 714 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 715 expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 716 expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION); 717 expectedCatch.add(utility.RUNTIME_EXCEPTION); 718 expectedCatch.add(utility.EXCEPTION); 719 assertEquals(expectedCatch, 720 utility.catchableSubset(unitAnalysis.mightThrow(arrayRef))); 721 } 722 723 public void testJDivExpr() { 724 Set vmAndArithmetic = new ExceptionHashSet(utility.VM_ERRORS); 725 vmAndArithmetic.add(utility.ARITHMETIC_EXCEPTION); 726 Set vmAndArithmeticAndSupertypes = 727 new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 728 vmAndArithmeticAndSupertypes.add(utility.ARITHMETIC_EXCEPTION); 729 vmAndArithmeticAndSupertypes.add(utility.RUNTIME_EXCEPTION); 730 vmAndArithmeticAndSupertypes.add(utility.EXCEPTION); 731 732 Local intLocal = Jimple.v().newLocal("intLocal", IntType.v()); 733 Local longLocal = Jimple.v().newLocal("longLocal", LongType.v()); 734 Local floatLocal = Jimple.v().newLocal("floatLocal", FloatType.v()); 735 Local doubleLocal = Jimple.v().newLocal("doubleLocal", DoubleType.v()); 736 737 DivExpr v = Jimple.v().newDivExpr(intLocal, IntConstant.v(0)); 738 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 739 unitAnalysis.mightThrow(v))); 740 assertEquals(vmAndArithmeticAndSupertypes, 741 utility.catchableSubset(unitAnalysis.mightThrow(v))); 742 743 v = Jimple.v().newDivExpr(intLocal, IntConstant.v(2)); 744 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 745 unitAnalysis.mightThrow(v))); 746 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 747 utility.catchableSubset(unitAnalysis.mightThrow(v))); 748 749 v = Jimple.v().newDivExpr(IntConstant.v(0), IntConstant.v(2)); 750 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 751 unitAnalysis.mightThrow(v))); 752 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 753 utility.catchableSubset(unitAnalysis.mightThrow(v))); 754 755 v = Jimple.v().newDivExpr(intLocal, intLocal); 756 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 757 unitAnalysis.mightThrow(v))); 758 assertEquals(vmAndArithmeticAndSupertypes, 759 utility.catchableSubset(unitAnalysis.mightThrow(v))); 760 761 v = Jimple.v().newDivExpr(longLocal, LongConstant.v(0)); 762 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 763 unitAnalysis.mightThrow(v))); 764 assertEquals(vmAndArithmeticAndSupertypes, 765 utility.catchableSubset(unitAnalysis.mightThrow(v))); 766 767 v = Jimple.v().newDivExpr(longLocal, LongConstant.v(2)); 768 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 769 unitAnalysis.mightThrow(v))); 770 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 771 utility.catchableSubset(unitAnalysis.mightThrow(v))); 772 773 v = Jimple.v().newDivExpr(LongConstant.v(0), LongConstant.v(2)); 774 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 775 unitAnalysis.mightThrow(v))); 776 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 777 utility.catchableSubset(unitAnalysis.mightThrow(v))); 778 779 v = Jimple.v().newDivExpr(longLocal, longLocal); 780 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 781 unitAnalysis.mightThrow(v))); 782 assertEquals(vmAndArithmeticAndSupertypes, 783 utility.catchableSubset(unitAnalysis.mightThrow(v))); 784 785 v = Jimple.v().newDivExpr(floatLocal, FloatConstant.v(0.0f)); 786 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 787 unitAnalysis.mightThrow(v))); 788 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 789 utility.catchableSubset(unitAnalysis.mightThrow(v))); 790 791 v = Jimple.v().newDivExpr(floatLocal, FloatConstant.v(2.0f)); 792 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 793 unitAnalysis.mightThrow(v))); 794 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 795 utility.catchableSubset(unitAnalysis.mightThrow(v))); 796 797 v = Jimple.v().newDivExpr(FloatConstant.v(0), FloatConstant.v(2.0f)); 798 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 799 unitAnalysis.mightThrow(v))); 800 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 801 utility.catchableSubset(unitAnalysis.mightThrow(v))); 802 803 v = Jimple.v().newDivExpr(floatLocal, floatLocal); 804 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 805 unitAnalysis.mightThrow(v))); 806 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 807 utility.catchableSubset(unitAnalysis.mightThrow(v))); 808 809 v = Jimple.v().newDivExpr(doubleLocal, DoubleConstant.v(0.0)); 810 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 811 unitAnalysis.mightThrow(v))); 812 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 813 utility.catchableSubset(unitAnalysis.mightThrow(v))); 814 815 v = Jimple.v().newDivExpr(doubleLocal, DoubleConstant.v(2.0)); 816 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 817 unitAnalysis.mightThrow(v))); 818 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 819 utility.catchableSubset(unitAnalysis.mightThrow(v))); 820 821 v = Jimple.v().newDivExpr(DoubleConstant.v(0), DoubleConstant.v(2.0)); 822 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 823 unitAnalysis.mightThrow(v))); 824 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 825 utility.catchableSubset(unitAnalysis.mightThrow(v))); 826 827 v = Jimple.v().newDivExpr(doubleLocal, doubleLocal); 828 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 829 unitAnalysis.mightThrow(v))); 830 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 831 utility.catchableSubset(unitAnalysis.mightThrow(v))); 832 } 833 834 public void testGDivExpr() { 835 Set vmAndArithmetic = new ExceptionHashSet(utility.VM_ERRORS); 836 vmAndArithmetic.add(utility.ARITHMETIC_EXCEPTION); 837 Set vmAndArithmeticAndSupertypes = 838 new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 839 vmAndArithmeticAndSupertypes.add(utility.ARITHMETIC_EXCEPTION); 840 vmAndArithmeticAndSupertypes.add(utility.RUNTIME_EXCEPTION); 841 vmAndArithmeticAndSupertypes.add(utility.EXCEPTION); 842 843 Local intLocal = Grimp.v().newLocal("intLocal", IntType.v()); 844 Local longLocal = Grimp.v().newLocal("longLocal", LongType.v()); 845 Local floatLocal = Grimp.v().newLocal("floatLocal", FloatType.v()); 846 Local doubleLocal = Grimp.v().newLocal("doubleLocal", DoubleType.v()); 847 848 DivExpr v = Grimp.v().newDivExpr(intLocal, IntConstant.v(0)); 849 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 850 unitAnalysis.mightThrow(v))); 851 assertEquals(vmAndArithmeticAndSupertypes, 852 utility.catchableSubset(unitAnalysis.mightThrow(v))); 853 854 v = Grimp.v().newDivExpr(intLocal, IntConstant.v(2)); 855 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 856 unitAnalysis.mightThrow(v))); 857 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 858 utility.catchableSubset(unitAnalysis.mightThrow(v))); 859 860 v = Grimp.v().newDivExpr(IntConstant.v(0), IntConstant.v(2)); 861 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 862 unitAnalysis.mightThrow(v))); 863 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 864 utility.catchableSubset(unitAnalysis.mightThrow(v))); 865 866 v = Grimp.v().newDivExpr(intLocal, intLocal); 867 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 868 unitAnalysis.mightThrow(v))); 869 assertEquals(vmAndArithmeticAndSupertypes, 870 utility.catchableSubset(unitAnalysis.mightThrow(v))); 871 872 v = Grimp.v().newDivExpr(Grimp.v().newAddExpr(intLocal, intLocal), 873 Grimp.v().newMulExpr(intLocal, intLocal)); 874 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 875 unitAnalysis.mightThrow(v))); 876 assertEquals(vmAndArithmeticAndSupertypes, 877 utility.catchableSubset(unitAnalysis.mightThrow(v))); 878 879 v = Grimp.v().newDivExpr(longLocal, LongConstant.v(0)); 880 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 881 unitAnalysis.mightThrow(v))); 882 assertEquals(vmAndArithmeticAndSupertypes, 883 utility.catchableSubset(unitAnalysis.mightThrow(v))); 884 885 v = Grimp.v().newDivExpr(longLocal, LongConstant.v(2)); 886 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 887 unitAnalysis.mightThrow(v))); 888 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 889 utility.catchableSubset(unitAnalysis.mightThrow(v))); 890 891 v = Grimp.v().newDivExpr(LongConstant.v(0), LongConstant.v(2)); 892 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 893 unitAnalysis.mightThrow(v))); 894 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 895 utility.catchableSubset(unitAnalysis.mightThrow(v))); 896 897 v = Grimp.v().newDivExpr(longLocal, longLocal); 898 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 899 unitAnalysis.mightThrow(v))); 900 assertEquals(vmAndArithmeticAndSupertypes, 901 utility.catchableSubset(unitAnalysis.mightThrow(v))); 902 903 v = Grimp.v().newDivExpr(Grimp.v().newAddExpr(longLocal, longLocal), 904 Grimp.v().newMulExpr(longLocal, longLocal)); 905 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 906 unitAnalysis.mightThrow(v))); 907 assertEquals(vmAndArithmeticAndSupertypes, 908 utility.catchableSubset(unitAnalysis.mightThrow(v))); 909 910 v = Grimp.v().newDivExpr(floatLocal, FloatConstant.v(0.0f)); 911 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 912 unitAnalysis.mightThrow(v))); 913 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 914 utility.catchableSubset(unitAnalysis.mightThrow(v))); 915 916 v = Grimp.v().newDivExpr(floatLocal, FloatConstant.v(2.0f)); 917 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 918 unitAnalysis.mightThrow(v))); 919 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 920 utility.catchableSubset(unitAnalysis.mightThrow(v))); 921 922 v = Grimp.v().newDivExpr(FloatConstant.v(0), FloatConstant.v(2.0f)); 923 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 924 unitAnalysis.mightThrow(v))); 925 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 926 utility.catchableSubset(unitAnalysis.mightThrow(v))); 927 928 v = Grimp.v().newDivExpr(floatLocal, floatLocal); 929 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 930 unitAnalysis.mightThrow(v))); 931 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 932 utility.catchableSubset(unitAnalysis.mightThrow(v))); 933 934 v = Grimp.v().newDivExpr(doubleLocal, DoubleConstant.v(0.0)); 935 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 936 unitAnalysis.mightThrow(v))); 937 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 938 utility.catchableSubset(unitAnalysis.mightThrow(v))); 939 940 v = Grimp.v().newDivExpr(doubleLocal, DoubleConstant.v(2.0)); 941 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 942 unitAnalysis.mightThrow(v))); 943 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 944 utility.catchableSubset(unitAnalysis.mightThrow(v))); 945 946 v = Grimp.v().newDivExpr(DoubleConstant.v(0), DoubleConstant.v(2.0)); 947 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 948 unitAnalysis.mightThrow(v))); 949 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 950 utility.catchableSubset(unitAnalysis.mightThrow(v))); 951 952 v = Grimp.v().newDivExpr(doubleLocal, doubleLocal); 953 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 954 unitAnalysis.mightThrow(v))); 955 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 956 utility.catchableSubset(unitAnalysis.mightThrow(v))); 957 } 958 959 public void testJRemExpr() { 960 Set vmAndArithmetic = new ExceptionHashSet(utility.VM_ERRORS); 961 vmAndArithmetic.add(utility.ARITHMETIC_EXCEPTION); 962 Set vmAndArithmeticAndSupertypes = 963 new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 964 vmAndArithmeticAndSupertypes.add(utility.ARITHMETIC_EXCEPTION); 965 vmAndArithmeticAndSupertypes.add(utility.RUNTIME_EXCEPTION); 966 vmAndArithmeticAndSupertypes.add(utility.EXCEPTION); 967 968 Local intLocal = Jimple.v().newLocal("intLocal", IntType.v()); 969 Local longLocal = Jimple.v().newLocal("longLocal", LongType.v()); 970 Local floatLocal = Jimple.v().newLocal("floatLocal", FloatType.v()); 971 Local doubleLocal = Jimple.v().newLocal("doubleLocal", DoubleType.v()); 972 973 RemExpr v = Jimple.v().newRemExpr(intLocal, IntConstant.v(0)); 974 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 975 unitAnalysis.mightThrow(v))); 976 assertEquals(vmAndArithmeticAndSupertypes, 977 utility.catchableSubset(unitAnalysis.mightThrow(v))); 978 979 v = Jimple.v().newRemExpr(intLocal, IntConstant.v(2)); 980 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 981 unitAnalysis.mightThrow(v))); 982 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 983 utility.catchableSubset(unitAnalysis.mightThrow(v))); 984 985 v = Jimple.v().newRemExpr(IntConstant.v(0), IntConstant.v(2)); 986 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 987 unitAnalysis.mightThrow(v))); 988 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 989 utility.catchableSubset(unitAnalysis.mightThrow(v))); 990 991 v = Jimple.v().newRemExpr(intLocal, intLocal); 992 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 993 unitAnalysis.mightThrow(v))); 994 assertEquals(vmAndArithmeticAndSupertypes, 995 utility.catchableSubset(unitAnalysis.mightThrow(v))); 996 997 v = Jimple.v().newRemExpr(longLocal, LongConstant.v(0)); 998 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 999 unitAnalysis.mightThrow(v))); 1000 assertEquals(vmAndArithmeticAndSupertypes, 1001 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1002 1003 v = Jimple.v().newRemExpr(longLocal, LongConstant.v(2)); 1004 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1005 unitAnalysis.mightThrow(v))); 1006 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1007 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1008 1009 v = Jimple.v().newRemExpr(LongConstant.v(0), LongConstant.v(2)); 1010 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1011 unitAnalysis.mightThrow(v))); 1012 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1013 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1014 1015 v = Jimple.v().newRemExpr(longLocal, longLocal); 1016 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 1017 unitAnalysis.mightThrow(v))); 1018 assertEquals(vmAndArithmeticAndSupertypes, 1019 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1020 1021 v = Jimple.v().newRemExpr(floatLocal, FloatConstant.v(0.0f)); 1022 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1023 unitAnalysis.mightThrow(v))); 1024 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1025 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1026 1027 v = Jimple.v().newRemExpr(floatLocal, FloatConstant.v(2.0f)); 1028 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1029 unitAnalysis.mightThrow(v))); 1030 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1031 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1032 1033 v = Jimple.v().newRemExpr(FloatConstant.v(0), FloatConstant.v(2.0f)); 1034 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1035 unitAnalysis.mightThrow(v))); 1036 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1037 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1038 1039 v = Jimple.v().newRemExpr(floatLocal, floatLocal); 1040 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1041 unitAnalysis.mightThrow(v))); 1042 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1043 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1044 1045 v = Jimple.v().newRemExpr(doubleLocal, DoubleConstant.v(0.0)); 1046 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1047 unitAnalysis.mightThrow(v))); 1048 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1049 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1050 1051 v = Jimple.v().newRemExpr(doubleLocal, DoubleConstant.v(2.0)); 1052 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1053 unitAnalysis.mightThrow(v))); 1054 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1055 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1056 1057 v = Jimple.v().newRemExpr(DoubleConstant.v(0), DoubleConstant.v(2.0)); 1058 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1059 unitAnalysis.mightThrow(v))); 1060 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1061 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1062 1063 v = Jimple.v().newRemExpr(doubleLocal, doubleLocal); 1064 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1065 unitAnalysis.mightThrow(v))); 1066 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1067 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1068 } 1069 1070 public void testGRemExpr() { 1071 Set vmAndArithmetic = new ExceptionHashSet(utility.VM_ERRORS); 1072 vmAndArithmetic.add(utility.ARITHMETIC_EXCEPTION); 1073 Set vmAndArithmeticAndSupertypes = 1074 new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 1075 vmAndArithmeticAndSupertypes.add(utility.ARITHMETIC_EXCEPTION); 1076 vmAndArithmeticAndSupertypes.add(utility.RUNTIME_EXCEPTION); 1077 vmAndArithmeticAndSupertypes.add(utility.EXCEPTION); 1078 1079 Local intLocal = Grimp.v().newLocal("intLocal", IntType.v()); 1080 Local longLocal = Grimp.v().newLocal("longLocal", LongType.v()); 1081 Local floatLocal = Grimp.v().newLocal("floatLocal", FloatType.v()); 1082 Local doubleLocal = Grimp.v().newLocal("doubleLocal", DoubleType.v()); 1083 1084 RemExpr v = Grimp.v().newRemExpr(intLocal, IntConstant.v(0)); 1085 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 1086 unitAnalysis.mightThrow(v))); 1087 assertEquals(vmAndArithmeticAndSupertypes, 1088 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1089 1090 v = Grimp.v().newRemExpr(intLocal, IntConstant.v(2)); 1091 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1092 unitAnalysis.mightThrow(v))); 1093 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1094 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1095 1096 v = Grimp.v().newRemExpr(IntConstant.v(0), IntConstant.v(2)); 1097 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1098 unitAnalysis.mightThrow(v))); 1099 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1100 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1101 1102 v = Grimp.v().newRemExpr(intLocal, intLocal); 1103 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 1104 unitAnalysis.mightThrow(v))); 1105 assertEquals(vmAndArithmeticAndSupertypes, 1106 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1107 1108 v = Grimp.v().newRemExpr(Grimp.v().newAddExpr(intLocal, intLocal), 1109 Grimp.v().newMulExpr(intLocal, intLocal)); 1110 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 1111 unitAnalysis.mightThrow(v))); 1112 assertEquals(vmAndArithmeticAndSupertypes, 1113 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1114 1115 v = Grimp.v().newRemExpr(longLocal, LongConstant.v(0)); 1116 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 1117 unitAnalysis.mightThrow(v))); 1118 assertEquals(vmAndArithmeticAndSupertypes, 1119 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1120 1121 v = Grimp.v().newRemExpr(longLocal, LongConstant.v(2)); 1122 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1123 unitAnalysis.mightThrow(v))); 1124 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1125 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1126 1127 v = Grimp.v().newRemExpr(LongConstant.v(0), LongConstant.v(2)); 1128 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1129 unitAnalysis.mightThrow(v))); 1130 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1131 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1132 1133 v = Grimp.v().newRemExpr(longLocal, longLocal); 1134 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 1135 unitAnalysis.mightThrow(v))); 1136 assertEquals(vmAndArithmeticAndSupertypes, 1137 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1138 1139 v = Grimp.v().newRemExpr(Grimp.v().newAddExpr(longLocal, longLocal), 1140 Grimp.v().newMulExpr(longLocal, longLocal)); 1141 assertTrue(utility.sameMembers(vmAndArithmetic, Collections.EMPTY_SET, 1142 unitAnalysis.mightThrow(v))); 1143 assertEquals(vmAndArithmeticAndSupertypes, 1144 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1145 1146 v = Grimp.v().newRemExpr(floatLocal, FloatConstant.v(0.0f)); 1147 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1148 unitAnalysis.mightThrow(v))); 1149 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1150 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1151 1152 v = Grimp.v().newRemExpr(floatLocal, FloatConstant.v(2.0f)); 1153 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1154 unitAnalysis.mightThrow(v))); 1155 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1156 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1157 1158 v = Grimp.v().newRemExpr(FloatConstant.v(0), FloatConstant.v(2.0f)); 1159 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1160 unitAnalysis.mightThrow(v))); 1161 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1162 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1163 1164 v = Grimp.v().newRemExpr(floatLocal, floatLocal); 1165 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1166 unitAnalysis.mightThrow(v))); 1167 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1168 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1169 1170 v = Grimp.v().newRemExpr(doubleLocal, DoubleConstant.v(0.0)); 1171 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1172 unitAnalysis.mightThrow(v))); 1173 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1174 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1175 1176 v = Grimp.v().newRemExpr(doubleLocal, DoubleConstant.v(2.0)); 1177 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1178 unitAnalysis.mightThrow(v))); 1179 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1180 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1181 1182 v = Grimp.v().newRemExpr(DoubleConstant.v(0), DoubleConstant.v(2.0)); 1183 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1184 unitAnalysis.mightThrow(v))); 1185 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1186 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1187 1188 v = Grimp.v().newRemExpr(doubleLocal, doubleLocal); 1189 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1190 unitAnalysis.mightThrow(v))); 1191 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1192 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1193 } 1194 1195 public void testJBinOpExp() { 1196 Value v = Jimple.v().newAddExpr(IntConstant.v(456), 1197 Jimple.v().newLocal("local", IntType.v())); 1198 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1199 unitAnalysis.mightThrow(v))); 1200 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1201 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1202 1203 v = Jimple.v().newOrExpr(Jimple.v().newLocal("local", LongType.v()), 1204 LongConstant.v(33)); 1205 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1206 unitAnalysis.mightThrow(v))); 1207 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1208 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1209 1210 v = Jimple.v().newLeExpr(Jimple.v().newLocal("local", FloatType.v()), 1211 FloatConstant.v(33.42f)); 1212 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1213 unitAnalysis.mightThrow(v))); 1214 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1215 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1216 1217 v = Jimple.v().newEqExpr(DoubleConstant.v(-33.45e-3), 1218 Jimple.v().newLocal("local", DoubleType.v())); 1219 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1220 unitAnalysis.mightThrow(v))); 1221 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1222 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1223 } 1224 1225 public void testGBinOpExp() { 1226 Value v = Grimp.v().newAddExpr(floatStaticFieldRef, floatConstant); 1227 assertTrue(utility.sameMembers(utility.ALL_ERRORS_REP, 1228 Collections.EMPTY_SET, 1229 unitAnalysis.mightThrow(v))); 1230 assertEquals(utility.ALL_TEST_ERRORS_PLUS_SUPERTYPES, 1231 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1232 1233 v = Grimp.v().newOrExpr(v, floatConstant); 1234 assertTrue(utility.sameMembers(utility.ALL_ERRORS_REP, 1235 Collections.EMPTY_SET, 1236 unitAnalysis.mightThrow(v))); 1237 assertEquals(utility.ALL_TEST_ERRORS_PLUS_SUPERTYPES, 1238 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1239 1240 Set expectedRep = new ExceptionHashSet(utility.ALL_ERRORS_REP); 1241 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 1242 1243 Set expectedCatch = new ExceptionHashSet(utility.ALL_TEST_ERRORS_PLUS_SUPERTYPES); 1244 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 1245 expectedCatch.add(utility.RUNTIME_EXCEPTION); 1246 expectedCatch.add(utility.EXCEPTION); 1247 1248 v = Grimp.v().newLeExpr(floatInstanceFieldRef, v); 1249 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1250 unitAnalysis.mightThrow(v))); 1251 assertEquals(expectedCatch, 1252 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1253 1254 v = Grimp.v().newEqExpr(v, floatVirtualInvoke); 1255 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1256 immaculateAnalysis.mightThrow(v))); 1257 assertEquals(expectedCatch, 1258 utility.catchableSubset(immaculateAnalysis.mightThrow(v))); 1259 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 1260 Collections.EMPTY_SET, 1261 unitAnalysis.mightThrow(v))); 1262 assertEquals(utility.ALL_TEST_THROWABLES, 1263 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1264 1265 expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 1266 expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION); 1267 expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION); 1268 1269 v = Grimp.v().newNeExpr(v, floatStaticInvoke); 1270 assertEquals(expectedCatch, 1271 utility.catchableSubset(immaculateAnalysis.mightThrow(v))); 1272 assertEquals(expectedCatch, 1273 utility.catchableSubset(immaculateAnalysis.mightThrow(v))); 1274 assertTrue(utility.sameMembers(utility.ALL_THROWABLES_REP, 1275 Collections.EMPTY_SET, 1276 unitAnalysis.mightThrow(v))); 1277 assertEquals(utility.ALL_TEST_THROWABLES, 1278 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1279 } 1280 1281 public void testJCastExpr() { 1282 Value v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", 1284 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR), 1285 utility.LINKAGE_ERROR); 1286 Set expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_REP); 1287 Set expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_PLUS_SUPERTYPES); 1288 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1289 unitAnalysis.mightThrow(v))); 1290 assertEquals(expectedCatch, 1291 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1292 1293 1294 v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", 1296 utility.LINKAGE_ERROR), 1297 utility.LINKAGE_ERROR); 1298 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1299 unitAnalysis.mightThrow(v))); 1300 assertEquals(expectedCatch, 1301 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1302 1303 v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", 1305 utility.LINKAGE_ERROR), 1306 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 1307 1308 expectedRep.add(utility.CLASS_CAST_EXCEPTION); 1309 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1310 unitAnalysis.mightThrow(v))); 1311 1312 expectedCatch.add(utility.CLASS_CAST_EXCEPTION); 1313 expectedCatch.add(utility.RUNTIME_EXCEPTION); 1314 expectedCatch.add(utility.EXCEPTION); 1315 1316 assertEquals(expectedCatch, 1317 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1318 } 1319 1320 public void testGCastExpr() { 1321 Value v = Grimp.v().newCastExpr(Jimple.v().newLocal("local", 1323 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR), 1324 utility.LINKAGE_ERROR); 1325 Set expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_REP); 1326 Set expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_CLASS_ERRORS_PLUS_SUPERTYPES); 1327 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1328 unitAnalysis.mightThrow(v))); 1329 assertEquals(expectedCatch, 1330 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1331 1332 1333 v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", 1335 utility.LINKAGE_ERROR), 1336 utility.LINKAGE_ERROR); 1337 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1338 unitAnalysis.mightThrow(v))); 1339 assertEquals(expectedCatch, 1340 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1341 1342 v = Jimple.v().newCastExpr(Jimple.v().newLocal("local", 1344 utility.LINKAGE_ERROR), 1345 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 1346 1347 expectedRep.add(utility.CLASS_CAST_EXCEPTION); 1348 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1349 unitAnalysis.mightThrow(v))); 1350 1351 expectedCatch.add(utility.CLASS_CAST_EXCEPTION); 1352 expectedCatch.add(utility.RUNTIME_EXCEPTION); 1353 expectedCatch.add(utility.EXCEPTION); 1354 1355 assertEquals(expectedCatch, 1356 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1357 } 1358 1359 public void testGInstanceFieldRef() { 1360 Local local = Grimp.v().newLocal("local", 1361 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 1362 1363 Set expectedRep = new ExceptionHashSet(utility.VM_AND_RESOLVE_FIELD_ERRORS_REP); 1364 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 1365 1366 Set expectedCatch = new ExceptionHashSet(utility.VM_AND_RESOLVE_FIELD_ERRORS_PLUS_SUPERTYPES); 1367 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 1368 expectedCatch.add(utility.RUNTIME_EXCEPTION); 1369 expectedCatch.add(utility.EXCEPTION); 1370 1371 Value v = Grimp.v().newInstanceFieldRef(local, 1372 Scene.v().makeFieldRef(utility.THROWABLE.getSootClass(), "detailMessage", 1373 RefType.v("java.lang.String"), false)); 1374 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1375 unitAnalysis.mightThrow(v))); 1376 assertEquals(expectedCatch, 1377 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1378 } 1379 1380 1381 public void testStringConstant() { 1382 Value v = StringConstant.v("test"); 1383 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1384 unitAnalysis.mightThrow(v))); 1385 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1386 utility.catchableSubset(unitAnalysis.mightThrow(v))); 1387 } 1388 1389 public void testJLocal() { 1390 Local local = Jimple.v().newLocal("local1", 1391 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 1392 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1393 unitAnalysis.mightThrow(local))); 1394 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1395 utility.catchableSubset(unitAnalysis.mightThrow(local))); 1396 } 1397 1398 public void testGLocal() { 1399 Local local = Grimp.v().newLocal("local1", 1400 utility.INCOMPATIBLE_CLASS_CHANGE_ERROR); 1401 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1402 unitAnalysis.mightThrow(local))); 1403 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1404 utility.catchableSubset(unitAnalysis.mightThrow(local))); 1405 } 1406 1407 public void testBAddInst() { 1408 soot.baf.AddInst i = soot.baf.Baf.v().newAddInst(IntType.v()); 1409 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1410 unitAnalysis.mightThrow(i))); 1411 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1412 utility.catchableSubset(unitAnalysis.mightThrow(i))); 1413 } 1414 1415 public void testBAndInst() { 1416 soot.baf.AndInst i = soot.baf.Baf.v().newAndInst(IntType.v()); 1417 assertTrue(utility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET, 1418 unitAnalysis.mightThrow(i))); 1419 assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 1420 utility.catchableSubset(unitAnalysis.mightThrow(i))); 1421 } 1422 1423 public void testBArrayLengthInst() { 1424 soot.baf.ArrayLengthInst i = soot.baf.Baf.v().newArrayLengthInst(); 1425 Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS); 1426 expectedRep.add(utility.NULL_POINTER_EXCEPTION); 1427 assertTrue(utility.sameMembers(expectedRep, Collections.EMPTY_SET, 1428 unitAnalysis.mightThrow(i))); 1429 Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES); 1430 expectedCatch.add(utility.NULL_POINTER_EXCEPTION); 1431 expectedCatch.add(utility.RUNTIME_EXCEPTION); 1432 expectedCatch.add(utility.EXCEPTION); 1433 assertEquals(expectedCatch, 1434 utility.catchableSubset(unitAnalysis.mightThrow(i))); 1435 } 1436 1437 1438 public static Test suite() { 1439 return new TestSuite(UnitThrowAnalysisTest.class); 1440 } 1441 1442 public static void main(String arg[]) { 1443 if (arg.length > 0) { 1444 jdkLocation = arg[0]; 1445 } 1446 junit.textui.TestRunner.run(suite()); 1447 } 1448} 1449 1450 | Popular Tags |