Skip to content

Commit

Permalink
Code Quality Improvement - Empty arrays and collections should be ret…
Browse files Browse the repository at this point in the history
…urned instead of null
  • Loading branch information
civanyp committed Dec 16, 2015
1 parent 99cdfa9 commit 4a5b292
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/alibaba/mtc/MtContextCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
import java.util.Collections;

/**
* {@link MtContextCallable} decorate {@link Callable}, so as to get {@link MtContextThreadLocal}
Expand Down Expand Up @@ -128,7 +129,7 @@ public static <T> List<MtContextCallable<T>> gets(Collection<? extends Callable<
*/
public static <T> List<MtContextCallable<T>> gets(Collection<? extends Callable<T>> tasks, boolean releaseMtContextAfterCall) {
if (null == tasks) {
return null;
return Collections.emptyList();
}
List<MtContextCallable<T>> copy = new ArrayList<MtContextCallable<T>>();
for (Callable<T> task : tasks) {
Expand All @@ -147,7 +148,7 @@ public static <T> List<MtContextCallable<T>> gets(Collection<? extends Callable<
*/
public static <T> List<MtContextCallable<T>> gets(Collection<? extends Callable<T>> tasks, boolean releaseMtContextAfterCall, boolean idempotent) {
if (null == tasks) {
return null;
return Collections.emptyList();
}
List<MtContextCallable<T>> copy = new ArrayList<MtContextCallable<T>>();
for (Callable<T> task : tasks) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/alibaba/mtc/MtContextRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.Collections;

/**
* {@link MtContextRunnable} decorate {@link Runnable}, so as to get {@link MtContextThreadLocal}
Expand Down Expand Up @@ -132,7 +133,7 @@ public static List<MtContextRunnable> gets(Collection<? extends Runnable> tasks)
*/
public static List<MtContextRunnable> gets(Collection<? extends Runnable> tasks, boolean releaseMtContextAfterRun) {
if (null == tasks) {
return null;
return Collections.emptyList();
}
List<MtContextRunnable> copy = new ArrayList<MtContextRunnable>();
for (Runnable task : tasks) {
Expand All @@ -153,7 +154,7 @@ public static List<MtContextRunnable> gets(Collection<? extends Runnable> tasks,
*/
public static List<MtContextRunnable> gets(Collection<? extends Runnable> tasks, boolean releaseMtContextAfterRun, boolean idempotent) {
if (null == tasks) {
return null;
return Collections.emptyList();
}
List<MtContextRunnable> copy = new ArrayList<MtContextRunnable>();
for (Runnable task : tasks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class MtContextTransformer implements ClassFileTransformer {
private static final String SCHEDULER_CLASS_FILE = "java.util.concurrent.ScheduledThreadPoolExecutor".replace('.', '/');

private static final String TIMER_TASK_CLASS_FILE = "java.util.TimerTask".replace('.', '/');
private static final byte[] EMPTY_BYTE_ARRAY = {};

private static String toClassName(String classFile) {
return classFile.replace('/', '.');
Expand Down Expand Up @@ -65,7 +66,7 @@ public byte[] transform(ClassLoader loader, String classFile, Class<?> classBein
if (TIMER_TASK_CLASS_FILE.equals(name)) {
logger.info("Transforming class " + className);
// FIXME add code here
return null;
return EMPTY_BYTE_ARRAY;
}
}
}
Expand All @@ -74,7 +75,7 @@ public byte[] transform(ClassLoader loader, String classFile, Class<?> classBein
logger.severe(msg);
throw new IllegalStateException(msg, t);
}
return null;
return EMPTY_BYTE_ARRAY;
}

private CtClass getCtClass(byte[] classFileBuffer, ClassLoader classLoader) throws IOException {
Expand Down

0 comments on commit 4a5b292

Please sign in to comment.