/** * {@inheritDoc} * * Return the actual object represented by this variable for a given scope */ @Override public Object getObject(Scope scope) throws CodeUnderTestException { Object arrayObject = array.getObject(scope); try { for (int idx = 0; idx < indices.size() - 1; idx++) { if (arrayObject == null) { throw new CodeUnderTestException(new NullPointerException()); } arrayObject = Array.get(arrayObject, indices.get(idx)); } if (arrayObject == null) { throw new CodeUnderTestException(new NullPointerException()); } Object result = Array.get(arrayObject, indices.get(indices.size() - 1)); return result; } catch (ArrayIndexOutOfBoundsException e) { throw new CodeUnderTestException(e); } }
/** {@inheritDoc} */ @Override public Throwable execute(Scope scope, PrintStream out) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException { Throwable exceptionThrown = null; // Add array variable to pool try { Class<?> componentType = retval.getComponentClass(); while (componentType.isArray()) componentType = componentType.getComponentType(); retval.setObject(scope, Array.newInstance(componentType, lengths)); } catch (CodeUnderTestException e) { exceptionThrown = e.getCause(); } return exceptionThrown; }
@Override public void afterStatement(Statement statement, Scope scope, Throwable exception) { if (statement instanceof EntityWithParametersStatement) { EntityWithParametersStatement parameterisedStatement = (EntityWithParametersStatement)statement; List<VariableReference> parRefs = parameterisedStatement.getParameterReferences(); List<Object> argObjects = new ArrayList<>(parRefs.size()); for (VariableReference parRef : parRefs) { Object parObject = null; try { if (parRef instanceof ArrayIndex || parRef instanceof FieldReference) { parObject = parRef.getObject(scope); } else if (parRef instanceof ConstantValue) { parObject = ((ConstantValue) parRef).getValue(); } else { parObject = parRef.getObject(scope); } } catch (CodeUnderTestException e) { e.printStackTrace(); } argObjects.add(parObject); } assert parRefs.size() == argObjects.size(); String className = parameterisedStatement.getDeclaringClassName(); String methodDesc = parameterisedStatement.getDescriptor(); String methodName = parameterisedStatement.getMethodName(); inputCoverage.put(statement.getPosition(), InputCoverageGoal.createCoveredGoalsFromParameters(className, methodName, methodDesc, argObjects)); // argumentsValues.put((EntityWithParametersStatement) statement, argObjects); } }
@Override public Throwable execute(Scope scope, PrintStream out) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException { if(!isStaticField) { try { Object receiver = parameters.get(1).getObject(scope); if (receiver == null) return new CodeUnderTestException(new NullPointerException()); } catch (CodeUnderTestException e) { return e; } } return super.execute(scope, out); } }
logger.warn("Not inlining test: " + e.getCause());
@Override public Throwable execute(final Scope scope, PrintStream out) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException { if(!isStaticMethod) { // If the callee is null, then reflection will only lead to a NPE. VariableReference callee = parameters.get(1); try { Object calleeObject = callee.getObject(scope); if(calleeObject == null) return new CodeUnderTestException(new NullPointerException()); } catch (CodeUnderTestException e) { return e; } } return super.execute(scope, out); }
@Override public Throwable execute(Scope scope, PrintStream out) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException { Throwable exceptionThrown = null; try { if(value == null) retval.setObject(scope, null); else { // String literals may not be longer than 32767 if(((String)value).length() >= 32767) throw new CodeUnderTestException(new IllegalArgumentException("Maximum string length exceeded")); // In the JUnit code we produce, strings are generated as // String foo = "bar"; // That means any reference comparison will behave different // as internally value is created as String foo = new String("bar"). // Therefore we have to use the string object in the constant pool retval.setObject(scope, value.intern()); } } catch (CodeUnderTestException e) { exceptionThrown = e; } return exceptionThrown; }
/** * {@inheritDoc} * * Return the actual object represented by this variable for a given scope */ @Override public Object getObject(Scope scope) throws CodeUnderTestException { Object s; if (field.isStatic()) { s = null; } else { s = source.getObject(scope); } try { return field.getField().get(s); } catch (IllegalArgumentException e) { logger.debug("Error accessing field " + field + " of object " + source + ": " + e, e); throw new CodeUnderTestException(e.getCause()); } catch (IllegalAccessException e) { logger.error("Error accessing field " + field + " of object " + source + ": " + e, e); throw new EvosuiteError(e); } catch (NullPointerException | ExceptionInInitializerError | NoClassDefFoundError e) { throw new CodeUnderTestException(e); } }
throw new CodeUnderTestException(new NullPointerException()); throw new CodeUnderTestException(new IllegalArgumentException( "Cannot assignable: " + value + " of class " + value.getClass() + " to field " + field throw new EvosuiteError(e); } catch (NullPointerException e) { throw new CodeUnderTestException(e); } catch (ExceptionInInitializerError e) { throw new CodeUnderTestException(e); } catch (NoClassDefFoundError e) { throw new EvosuiteError(e);
for (int idx = 0; idx < indices.size() - 1; idx++) { if (arrayObject == null) { throw new CodeUnderTestException(new NullPointerException()); throw new CodeUnderTestException(new NullPointerException()); throw new CodeUnderTestException(new NullPointerException()); throw new CodeUnderTestException(e);
throw new CodeUnderTestException( new UncompilableCodeException("Cannot assign "+parameterVar.getVariableClass().getName() +" to "+parameterTypes[i])); throw new CodeUnderTestException(new NullPointerException()); if (inputs[0] == null) { throw new CodeUnderTestException(new NullPointerException());
throw new CodeUnderTestException(new NullPointerException()); throw new CodeUnderTestException(new ClassCastException());
inputs[i] = parameterVar.getObject(scope); if(inputs[i] == null && method.getMethod().getParameterTypes()[i].isPrimitive()) { throw new CodeUnderTestException(new NullPointerException()); throw new CodeUnderTestException( new UncompilableCodeException("Cannot assign "+parameterVar.getVariableClass().getName() +" to "+parameterTypes[i])); : callee.getObject(scope); if (!method.isStatic() && callee_object == null) { throw new CodeUnderTestException(new NullPointerException()); && ret != null && !returnClass.isAssignableFrom(ret.getClass())) { throw new CodeUnderTestException(new ClassCastException( "Cannot assign " + method.getReturnType() + " to variable of type " + retval.getType()));
throw new CodeUnderTestException(e); if (k >= parameters.size()) { throw new CodeUnderTestException(new FalsePositiveException("EvoSuite ERROR: index " + k + " out of " + parameters.size())); codeUnderTestException = new CodeUnderTestException(new NullPointerException()); codeUnderTestException = new CodeUnderTestException( new UncompilableCodeException("Cannot assign " + parameterVar.getVariableClass().getName() + " to " + method.getReturnType())); throw new CodeUnderTestException(e); //or should throw an exception? } catch (Throwable t) { AtMostOnceLogger.error(logger, "Failed to use Mockito on " + targetClass + ": " + t.getMessage());
@Override public void execute() throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException, CodeUnderTestException { try { final Object value = parameter.getObject(scope); if (checkNullDereference(scope)) { throw new CodeUnderTestException(new NullPointerException()); } retval.setObject(scope, value); //} catch (CodeUnderTestException e) { // throw CodeUnderTestException.throwException(e.getCause()); } catch (IllegalArgumentException e) { logger.error("Error assigning value of type " + parameter.getSimpleClassName() + " defined at statement " + tc.getStatement(parameter.getStPosition()).getCode() + ", assignment statement: " + tc.getStatement(retval.getStPosition()).getCode() + "; SUT=" + Properties.TARGET_CLASS); // FIXXME: IllegalArgumentException may happen when we only have generators // for an abstract supertype and not the concrete type that we need! throw e; } catch (CodeUnderTestException e) { throw e; } catch (Throwable e) { throw new EvosuiteError(e); } }