Skip to content

Commit

Permalink
Fixed #119 : We have now fixed the deprecated newInstance() method. A…
Browse files Browse the repository at this point in the history
…lso we have encpsulated exceptions into a try catch
  • Loading branch information
baubakg committed Jun 14, 2024
1 parent 55e9689 commit c66f856
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
*/
package com.adobe.campaign.tests.logparser.core;

import java.io.*;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import com.adobe.campaign.tests.logparser.exceptions.StringParseException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.adobe.campaign.tests.logparser.exceptions.StringParseException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

public class StringParseFactory {

Expand All @@ -44,20 +42,13 @@ private StringParseFactory() {
* @param <T> The type of data (subclass of {@link StdLogEntry}) we want to create and store
* @param <V> The collection type with which we receive the parameter in_logFiles
* @return A map of String and a Sub-class of {@link StdLogEntry}
* @throws InstantiationException
* if this {@code Class} represents an abstract class, an interface,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
* @throws IllegalAccessException
* if the class or its nullary constructor is not accessible.
* @throws StringParseException
* When there are logical rules when parsing the given string
*
*/
public static <T extends StdLogEntry, V extends Collection<String>> Map<String, T> extractLogEntryMap(
final V in_logFiles, ParseDefinition in_parseDefinition, Class<T> in_classTarget)
throws InstantiationException, IllegalAccessException, StringParseException {
throws StringParseException {

if (in_logFiles.isEmpty()) {
log.warn(
Expand Down Expand Up @@ -126,18 +117,21 @@ public static <T extends StdLogEntry, V extends Collection<String>> Map<String,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
* @throws IllegalAccessException
* if the class or its nullary constructor is not accessible.
* @throws StringParseException
* When there are logical rules when parsing the given string
*
*/
static <T extends StdLogEntry> void updateEntryMapWithParsedData(final String in_logLine,
ParseDefinition in_parseDefinition, Map<String, T> in_entries, Class<T> in_classTarget)
throws InstantiationException, IllegalAccessException, StringParseException {
throws StringParseException {
Map<String, String> lt_lineResult = StringParseFactory.parseString(in_logLine, in_parseDefinition);

T lt_entry = in_classTarget.newInstance();
T lt_entry = null;
try {
lt_entry = in_classTarget.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Missing Default constructor in SDK Parser Class", e);
}

lt_entry.setParseDefinition(in_parseDefinition);
lt_entry.setValuesFromMap(lt_lineResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void testItems() throws StringParseException {
}

@Test
public void testUpdateMap() throws InstantiationException, IllegalAccessException, StringParseException {
public void testUpdateMap() throws StringParseException {

String l_accLogString = "INFO | 25-May-2020 03:29:28:097 | - (SOAPutils.java:434) - HEADER ACTION xtk:persist#NewInstance";

Expand Down

0 comments on commit c66f856

Please sign in to comment.