@Test public void testSearchForNonPrivateMethods_withPublicCaller(){ BytecodeInstruction stmt = Mockito.mock(BytecodeInstruction.class); Mockito.doReturn("java.lang.Integer").when(stmt).getClassName(); Mockito.doReturn("reverse()").when(stmt).getMethodName(); Mockito.doReturn(1).when(stmt).getLineNumber(); List<BytecodeInstruction> instructions = new ArrayList<>(); instructions.add(stmt); ActualControlFlowGraph actualCFG = mockActualControlFlowGraph(stmt, true); Mockito.doReturn(actualCFG).when(stmt).getActualCFG(); RawControlFlowGraph rawCFG = mockRawControlFlowGraph(stmt, "reverse"); Mockito.doReturn(rawCFG).when(stmt).getRawCFG(); GuidedSearchUtility utility = new GuidedSearchUtility(); utility.searchForNonPrivateMethods(instructions, stmt); }
protected void searchForNonPrivateMethods(List<BytecodeInstruction> instructions, BytecodeInstruction targetInstruction){ LinkedList<String> callers = new LinkedList<String>(); Set<String> visitedMethods = new HashSet<String>(); HashMap<BytecodeInstruction, ArrayList<String>> CUTMethods = new HashMap<>(); callers.add(targetInstruction.getActualCFG().getMethodName()); for (BytecodeInstruction instruct : instructions) { if(!CUTMethods.containsKey(instruct)) { ArrayList<String> calledMethods = new ArrayList<>(); for (BytecodeInstruction method_call : instruct.getRawCFG().determineMethodCalls()){ calledMethods.add(method_call.getCalledMethod()); } CUTMethods.put(instruct, calledMethods); } } while (callers.size()>0){ String privateMethod = callers.removeFirst(); if (visitedMethods.contains(privateMethod)) { continue; }else { visitedMethods.add(privateMethod); } for( BytecodeInstruction key : CUTMethods.keySet()) { ArrayList<String> list = CUTMethods.get(key); for (String invokedMethod : list) { if (invokedMethod.equals(privateMethod)) { if(!isPrivateMethod(key.getActualCFG())){ publicCallsBC.add(key); }else { callers.addLast(key.getMethodName()); } } } } } }
GuidedSearchUtility { protected void searchForNonPrivateMethods(List<BytecodeInstruction> instructions, BytecodeInstruction targetInstruction){ LinkedList<String> callers = new LinkedList<String>(); Set<String> visitedMethods = new HashSet<String>(); HashMap<BytecodeInstruction, ArrayList<String>> CUTMethods = new HashMap<>(); callers.add(targetInstruction.getActualCFG().getMethodName()); for (BytecodeInstruction instruct : instructions) { if(!CUTMethods.containsKey(instruct)) { ArrayList<String> calledMethods = new ArrayList<>(); for (BytecodeInstruction method_call : instruct.getRawCFG().determineMethodCalls()){ calledMethods.add(method_call.getCalledMethod()); } CUTMethods.put(instruct, calledMethods); } } while (callers.size()>0){ String privateMethod = callers.removeFirst(); if (visitedMethods.contains(privateMethod)) { continue; }else { visitedMethods.add(privateMethod); } for( BytecodeInstruction key : CUTMethods.keySet()) { ArrayList<String> list = CUTMethods.get(key); for (String invokedMethod : list) { if (invokedMethod.equals(privateMethod)) { if(!isPrivateMethod(key.getActualCFG())){ publicCallsBC.add(key); }else { callers.addLast(key.getMethodName()); } } } } } } }
GuidedSearchUtility { protected void searchForNonPrivateMethods(List<BytecodeInstruction> instructions, BytecodeInstruction targetInstruction){ LinkedList<String> callers = new LinkedList<String>(); Set<String> visitedMethods = new HashSet<String>(); HashMap<BytecodeInstruction, ArrayList<String>> CUTMethods = new HashMap<>(); callers.add(targetInstruction.getActualCFG().getMethodName()); for (BytecodeInstruction instruct : instructions) { if(!CUTMethods.containsKey(instruct)) { ArrayList<String> calledMethods = new ArrayList<>(); for (BytecodeInstruction method_call : instruct.getRawCFG().determineMethodCalls()){ calledMethods.add(method_call.getCalledMethod()); } CUTMethods.put(instruct, calledMethods); } } while (callers.size()>0){ String privateMethod = callers.removeFirst(); if (visitedMethods.contains(privateMethod)) { continue; }else { visitedMethods.add(privateMethod); } for( BytecodeInstruction key : CUTMethods.keySet()) { ArrayList<String> list = CUTMethods.get(key); for (String invokedMethod : list) { if (invokedMethod.equals(privateMethod)) { if(!isPrivateMethod(key.getActualCFG())){ publicCallsBC.add(key); }else { callers.addLast(key.getMethodName()); } } } } } }  }
GuidedSearchUtility { protected void searchForNonPrivateMethods(List<BytecodeInstruction> instructions, BytecodeInstruction targetInstruction){ LinkedList<String> callers = new LinkedList<String>(); Set<String> visitedMethods = new HashSet<String>(); HashMap<BytecodeInstruction, ArrayList<String>> CUTMethods = new HashMap<>(); callers.add(targetInstruction.getActualCFG().getMethodName()); for (BytecodeInstruction instruct : instructions) { if(!CUTMethods.containsKey(instruct)) { ArrayList<String> calledMethods = new ArrayList<>(); for (BytecodeInstruction method_call : instruct.getRawCFG().determineMethodCalls()){ calledMethods.add(method_call.getCalledMethod()); } CUTMethods.put(instruct, calledMethods); } } while (callers.size()>0){ String privateMethod = callers.removeFirst(); if (visitedMethods.contains(privateMethod)) { continue; }else { visitedMethods.add(privateMethod); } for( BytecodeInstruction key : CUTMethods.keySet()) { ArrayList<String> list = CUTMethods.get(key); for (String invokedMethod : list) { if (invokedMethod.equals(privateMethod)) { if(!isPrivateMethod(key.getActualCFG())){ publicCallsBC.add(key); }else { callers.addLast(key.getMethodName()); } } } } } }  BytecodeInstruction collectPublicCalls(StackTrace trace); boolean includesPublicCall(T individual, Set<GenericAccessibleObject<?>> publicCalls); }
GuidedSearchUtility { protected void searchForNonPrivateMethods(List<BytecodeInstruction> instructions, BytecodeInstruction targetInstruction){ LinkedList<String> callers = new LinkedList<String>(); Set<String> visitedMethods = new HashSet<String>(); HashMap<BytecodeInstruction, ArrayList<String>> CUTMethods = new HashMap<>(); callers.add(targetInstruction.getActualCFG().getMethodName()); for (BytecodeInstruction instruct : instructions) { if(!CUTMethods.containsKey(instruct)) { ArrayList<String> calledMethods = new ArrayList<>(); for (BytecodeInstruction method_call : instruct.getRawCFG().determineMethodCalls()){ calledMethods.add(method_call.getCalledMethod()); } CUTMethods.put(instruct, calledMethods); } } while (callers.size()>0){ String privateMethod = callers.removeFirst(); if (visitedMethods.contains(privateMethod)) { continue; }else { visitedMethods.add(privateMethod); } for( BytecodeInstruction key : CUTMethods.keySet()) { ArrayList<String> list = CUTMethods.get(key); for (String invokedMethod : list) { if (invokedMethod.equals(privateMethod)) { if(!isPrivateMethod(key.getActualCFG())){ publicCallsBC.add(key); }else { callers.addLast(key.getMethodName()); } } } } } }  BytecodeInstruction collectPublicCalls(StackTrace trace); boolean includesPublicCall(T individual, Set<GenericAccessibleObject<?>> publicCalls); public Set<BytecodeInstruction> publicCallsBC; }