@Test void readValueThrowsExceptionsThrowingConstructors() { IllegalArgumentException exception = assertThrows( IllegalArgumentException.class, () -> AutoValueReflection.readValue( Collections.emptyMap(), ThrowsOnConstructorInput.class)); assertThat(exception.getMessage(), containsString("Couldn't instantiate class")); }
static <T> T readValue(Map<String, Literal> inputs, Class<T> cls) { Map<String, Object> inputValues = toJavaMap(inputs); Constructor<T> constructor = getAutoValueConstructor(cls); Object[] paramValues = Arrays.stream(constructor.getParameters()) .map(param -> getParamValue(inputValues, param)) .toArray(); try { if (!constructor.isAccessible()) { constructor.setAccessible(true); } return constructor.newInstance(paramValues); } catch (Exception e) { throw new IllegalArgumentException( String.format( "Couldn't instantiate class [%s] with values [%s]", constructor.getDeclaringClass(), inputs), e); } }
AutoValueReflection { static <T> T readValue(Map<String, Literal> inputs, Class<T> cls) { Map<String, Object> inputValues = toJavaMap(inputs); Constructor<T> constructor = getAutoValueConstructor(cls); Object[] paramValues = Arrays.stream(constructor.getParameters()) .map(param -> getParamValue(inputValues, param)) .toArray(); try { if (!constructor.isAccessible()) { constructor.setAccessible(true); } return constructor.newInstance(paramValues); } catch (Exception e) { throw new IllegalArgumentException( String.format( "Couldn't instantiate class [%s] with values [%s]", constructor.getDeclaringClass(), inputs), e); } } }
AutoValueReflection { static <T> T readValue(Map<String, Literal> inputs, Class<T> cls) { Map<String, Object> inputValues = toJavaMap(inputs); Constructor<T> constructor = getAutoValueConstructor(cls); Object[] paramValues = Arrays.stream(constructor.getParameters()) .map(param -> getParamValue(inputValues, param)) .toArray(); try { if (!constructor.isAccessible()) { constructor.setAccessible(true); } return constructor.newInstance(paramValues); } catch (Exception e) { throw new IllegalArgumentException( String.format( "Couldn't instantiate class [%s] with values [%s]", constructor.getDeclaringClass(), inputs), e); } } private  AutoValueReflection(); }
AutoValueReflection { static <T> T readValue(Map<String, Literal> inputs, Class<T> cls) { Map<String, Object> inputValues = toJavaMap(inputs); Constructor<T> constructor = getAutoValueConstructor(cls); Object[] paramValues = Arrays.stream(constructor.getParameters()) .map(param -> getParamValue(inputValues, param)) .toArray(); try { if (!constructor.isAccessible()) { constructor.setAccessible(true); } return constructor.newInstance(paramValues); } catch (Exception e) { throw new IllegalArgumentException( String.format( "Couldn't instantiate class [%s] with values [%s]", constructor.getDeclaringClass(), inputs), e); } } private  AutoValueReflection();  }
AutoValueReflection { static <T> T readValue(Map<String, Literal> inputs, Class<T> cls) { Map<String, Object> inputValues = toJavaMap(inputs); Constructor<T> constructor = getAutoValueConstructor(cls); Object[] paramValues = Arrays.stream(constructor.getParameters()) .map(param -> getParamValue(inputValues, param)) .toArray(); try { if (!constructor.isAccessible()) { constructor.setAccessible(true); } return constructor.newInstance(paramValues); } catch (Exception e) { throw new IllegalArgumentException( String.format( "Couldn't instantiate class [%s] with values [%s]", constructor.getDeclaringClass(), inputs), e); } } private  AutoValueReflection();   }