Skip to content

Commit

Permalink
Code analysis issues 2 (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaa4eb committed Jul 6, 2024
1 parent 1c7fbae commit c1e3874
Show file tree
Hide file tree
Showing 109 changed files with 731 additions and 854 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ private static OverridableRecordingPolicy initializePolicy(Settings settings) {
policy = new DelayBasedRecordingPolicy(Duration.ofSeconds(Integer.parseInt(value.replace("delay:", ""))));
} else if (value.equals("api")) {
policy = new DisabledRecordingPolicy();
} else if (value.startsWith("file:")) {
policy = new FileBasedStartRecordingPolicy(Paths.get(value.replace("file:", "")));
} else {
throw new IllegalArgumentException("Unsupported recording policy: " + value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.io.PrintStream;

/**
* Forked from slf4j-simple
*/
class OutputChoice {

enum OutputChoiceType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.ulyp.agent.AgentContext;
import com.ulyp.agent.RecorderInstance;


/**
* Forked from slf4j-simple
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,37 @@

import org.slf4j.helpers.Util;

/**
* Forked from slf4j-simple
*/
public class SimpleLoggerConfiguration {

private static final String CONFIGURATION_FILE = "simplelogger.properties";

static int DEFAULT_LOG_LEVEL_DEFAULT = SimpleLogger.LOG_LEVEL_INFO;
int defaultLogLevel = DEFAULT_LOG_LEVEL_DEFAULT;

private static final boolean SHOW_THREAD_NAME_DEFAULT = true;
private static final boolean SHOW_DATE_TIME_DEFAULT = false;
boolean showDateTime = SHOW_DATE_TIME_DEFAULT;

private static final String DATE_TIME_FORMAT_STR_DEFAULT = null;
private static String dateTimeFormatStr = DATE_TIME_FORMAT_STR_DEFAULT;
private static int DEFAULT_LOG_LEVEL_DEFAULT = SimpleLogger.LOG_LEVEL_INFO;
private final static boolean SHOW_LOG_NAME_DEFAULT = true;
private static final boolean SHOW_SHORT_LOG_NAME_DEFAULT = false;
private static final boolean LEVEL_IN_BRACKETS_DEFAULT = false;
private static String LOG_FILE_DEFAULT = "System.err";
private static final boolean CACHE_OUTPUT_STREAM_DEFAULT = false;
private static final String WARN_LEVELS_STRING_DEFAULT = "WARN";

int defaultLogLevel = DEFAULT_LOG_LEVEL_DEFAULT;
boolean showDateTime = SHOW_DATE_TIME_DEFAULT;
DateFormat dateFormatter = null;

private static final boolean SHOW_THREAD_NAME_DEFAULT = true;
boolean showThreadName = SHOW_THREAD_NAME_DEFAULT;

final static boolean SHOW_LOG_NAME_DEFAULT = true;
boolean showLogName = SHOW_LOG_NAME_DEFAULT;

private static final boolean SHOW_SHORT_LOG_NAME_DEFAULT = false;
boolean showShortLogName = SHOW_SHORT_LOG_NAME_DEFAULT;

private static final boolean LEVEL_IN_BRACKETS_DEFAULT = false;
boolean levelInBrackets = LEVEL_IN_BRACKETS_DEFAULT;

private static String LOG_FILE_DEFAULT = "System.err";
private String logFile = LOG_FILE_DEFAULT;
OutputChoice outputChoice = null;

private static final boolean CACHE_OUTPUT_STREAM_DEFAULT = false;
private boolean cacheOutputStream = CACHE_OUTPUT_STREAM_DEFAULT;

private static final String WARN_LEVELS_STRING_DEFAULT = "WARN";
String warnLevelString = WARN_LEVELS_STRING_DEFAULT;

private boolean cacheOutputStream = CACHE_OUTPUT_STREAM_DEFAULT;
private final Properties properties = new Properties();

void init() {
Expand Down Expand Up @@ -122,7 +116,7 @@ String getStringProperty(String name) {
try {
prop = System.getProperty(name);
} catch (SecurityException e) {
; // Ignore
// Ignore
}
return (prop == null) ? properties.getProperty(name) : prop;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

/**
* Forked from slf4j-simple
*/
public class SimpleLoggerFactory implements ILoggerFactory {

ConcurrentMap<String, SimpleLogger> loggerMap;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ private void processEvents() {
sequence.set(availableSequence);
} catch (final AlertException ex) {
if (status.get() != RUNNING) {
break;
return;
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
break;
} catch (final Throwable ex) {
return;
} catch (Exception ex) {
sequence.set(nextSequence);
nextSequence++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void run() {
if (!running.get()) {
break;
}
} catch (final Throwable ex) {
} catch (Exception ex) {
// handle, mark as processed, unless the exception handler threw an exception
exceptionHandler.handleEventException(ex, nextSequence, event);
processedSequence = true;
Expand All @@ -128,7 +128,7 @@ private void notifyStart() {
if (workHandler instanceof LifecycleAware) {
try {
((LifecycleAware) workHandler).onStart();
} catch (final Throwable ex) {
} catch (Exception ex) {
exceptionHandler.handleOnStartException(ex);
}
}
Expand All @@ -138,7 +138,7 @@ private void notifyShutdown() {
if (workHandler instanceof LifecycleAware) {
try {
((LifecycleAware) workHandler).onShutdown();
} catch (final Throwable ex) {
} catch (Exception ex) {
exceptionHandler.handleOnShutdownException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.agent.tests.concurrent.classes;

// Automatically generated and only used for instrumentation tests
// Automatically generated and only used for instrumentation tests. The code is meaningless and has only single purpose - code analysis should not hate it too much
@SuppressWarnings("unused")
public class X0 {
public int m1(int a, int b, int c) {
Expand Down Expand Up @@ -30,27 +30,27 @@ public int m5(short a, short b, short c) {

public String m8(Integer x, Long y, Long z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z + x);
}

public String m9(Integer x, Long y, Long z, String suffix) {
System.out.println("1");
return y + z + suffix;
return x + y + z + suffix;
}

public String m10(String prefix, Integer x, Long y, Long z, String suffix) {
System.out.println("1");
return prefix + y + z + suffix;
return prefix + x + y + z + suffix;
}

public String m11(Integer x, Long y, Long z) {
public String m11(Float x, Double y, Double z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z + x);
}

public String m12(Integer x, Long y, Long z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z) + x;
}

public void m13() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.agent.tests.concurrent.classes;

// Automatically generated and only used for instrumentation tests
// Automatically generated and only used for instrumentation tests. The code is meaningless and has only single purpose - code analysis should not hate it too much
@SuppressWarnings("unused")
public class X1 {
public int m1(int a, int b, int c) {
Expand Down Expand Up @@ -30,27 +30,27 @@ public int m5(short a, short b, short c) {

public String m8(Integer x, Long y, Long z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z + x);
}

public String m9(Integer x, Long y, Long z, String suffix) {
System.out.println("1");
return y + z + suffix;
return x + y + z + suffix;
}

public String m10(String prefix, Integer x, Long y, Long z, String suffix) {
System.out.println("1");
return prefix + y + z + suffix;
return prefix + x + y + z + suffix;
}

public String m11(Integer x, Long y, Long z) {
public String m11(Float x, Double y, Double z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z + x);
}

public String m12(Integer x, Long y, Long z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z) + x;
}

public void m13() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.agent.tests.concurrent.classes;

// Automatically generated and only used for instrumentation tests
// Automatically generated and only used for instrumentation tests. The code is meaningless and has only single purpose - code analysis should not hate it too much
@SuppressWarnings("unused")
public class X10 {
public int m1(int a, int b, int c) {
Expand Down Expand Up @@ -30,27 +30,27 @@ public int m5(short a, short b, short c) {

public String m8(Integer x, Long y, Long z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z + x);
}

public String m9(Integer x, Long y, Long z, String suffix) {
System.out.println("1");
return y + z + suffix;
return x + y + z + suffix;
}

public String m10(String prefix, Integer x, Long y, Long z, String suffix) {
System.out.println("1");
return prefix + y + z + suffix;
return prefix + x + y + z + suffix;
}

public String m11(Integer x, Long y, Long z) {
public String m11(Float x, Double y, Double z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z + x);
}

public String m12(Integer x, Long y, Long z) {
System.out.println("1");
return String.valueOf(y + z);
return String.valueOf(y + z) + x;
}

public void m13() {
Expand Down
Loading

0 comments on commit c1e3874

Please sign in to comment.