Fix Extract this nested try block into a separate method
Fix Either log or rethrow this exception
Fix Remove this throw statement from this finally block
Issue-ID: DCAEGEN2-1384
Change-Id: Icb9a376a57d0ec2466c679f821fb0d346df769e7
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
final Class<?> objectClass = object.getClass();
try {
final Field privateField = objectClass.getDeclaredField(fieldName);
final Class<?> objectClass = object.getClass();
try {
final Field privateField = objectClass.getDeclaredField(fieldName);
- // mark private field to be accessible for testing purposes
- AccessController.doPrivileged((PrivilegedAction) () -> {
- privateField.setAccessible(true);
- return null;
- });
+ // mark private field to be accessible for testing purposes
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ privateField.setAccessible(true);
+ return null;
+ });
- return privateFieldClass.cast(privateField.get(object));
+ return privateFieldClass.cast(privateField.get(object));
- } catch (IllegalAccessException e) {
- logger.error("Unable to access field: {}", fieldName);
- throw new IllegalStateException(e);
- }
+ } catch (IllegalAccessException e) {
+ logger.error("Unable to access field: {}", fieldName);
+ throw new IllegalStateException(e);
} catch (NoSuchFieldException e) {
} catch (NoSuchFieldException e) {
- logger.error("Unable to locate field name: {} in class: {}", fieldName, objectClass.getSimpleName());
+ logger.error("Unable to locate field name: {} in class: {}", fieldName,
+ objectClass.getSimpleName());
throw new IllegalStateException(e);
}
throw new IllegalStateException(e);
}
*/
public static <T> T deserializeJsonFileToModel(final String jsonFileLocation, final Class<T> modelClass,
final ObjectMapper objectMapper) {
*/
public static <T> T deserializeJsonFileToModel(final String jsonFileLocation, final Class<T> modelClass,
final ObjectMapper objectMapper) {
- final InputStream jsonFileInputStream =
- BaseAnalyticsTest.class.getClassLoader().getResourceAsStream(jsonFileLocation);
- assertThat(jsonFileInputStream).as("Input JSON File location must be valid").isNotNull();
- try {
+ try( final InputStream jsonFileInputStream =
+ BaseAnalyticsTest.class.getClassLoader().getResourceAsStream(jsonFileLocation)) {
+ assertThat(jsonFileInputStream).as("Input JSON File location must be valid").isNotNull();
return objectMapper.readValue(jsonFileInputStream, modelClass);
} catch (IOException ex) {
logger.error("Error while doing assert Json for fileLocation: {}, modelClass: {}, Exception {}",
jsonFileLocation, modelClass, ex);
throw new RuntimeException(ex);
return objectMapper.readValue(jsonFileInputStream, modelClass);
} catch (IOException ex) {
logger.error("Error while doing assert Json for fileLocation: {}, modelClass: {}, Exception {}",
jsonFileLocation, modelClass, ex);
throw new RuntimeException(ex);
- } finally {
- try {
- jsonFileInputStream.close();
- } catch (IOException e) {
- logger.error("Error while closing input stream at file location: {}", jsonFileLocation);
- throw new RuntimeException(e);
- }
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
cienv.putAll(testEnvironmentVariables);
} catch (NoSuchFieldException e) {
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
cienv.putAll(testEnvironmentVariables);
} catch (NoSuchFieldException e) {
+ logger.error("NoSuchFieldException in setEnvironmentVariables", e);
Class[] classes = Collections.class.getDeclaredClasses();
Map<String, String> env = System.getenv();
for (Class cl : classes) {
Class[] classes = Collections.class.getDeclaredClasses();
Map<String, String> env = System.getenv();
for (Class cl : classes) {