Skip to content

Commit 3175265

Browse files
authored
Formatting and making some methods private (#417)
Apply formatting, revisit methods visibility in `EventHandlerLoader`
1 parent 96ceea1 commit 3175265

19 files changed

+120
-123
lines changed

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/AWSLambda.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ private static LogSink createLogSink() {
182182
}
183183

184184
public static void main(String[] args) {
185-
// TODO validate arguments, show usage
186185
startRuntime(args[0]);
187186
}
188187

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/ClasspathLoader.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/**
1515
* This class loads all of the classes that are in jars on the classpath.
16-
*
16+
* <p>
1717
* It is used to generate a class list and Application CDS archive that includes all the possible classes that could be
1818
* loaded by the runtime. This simplifies the process of generating the Application CDS archive.
1919
*/
@@ -38,7 +38,7 @@ private static void loadClass(String name) {
3838
try {
3939
Class.forName(name, true, SYSTEM_CLASS_LOADER);
4040
} catch (ClassNotFoundException e) {
41-
System.err.println("[WARN] Failed to load " + name + ": " + e.getMessage());
41+
System.err.println("[WARN] Failed to load " + name + ": " + e.getMessage());
4242
}
4343
}
4444

@@ -48,13 +48,13 @@ private static void loadClassesInJar(File file) throws IOException {
4848
while (en.hasMoreElements()) {
4949
JarEntry entry = en.nextElement();
5050

51-
if(!entry.getName().endsWith(".class")) {
51+
if (!entry.getName().endsWith(".class")) {
5252
continue;
5353
}
5454

5555
String name = pathToClassName(entry.getName());
5656

57-
if(BLOCKLIST.contains(name)) {
57+
if (BLOCKLIST.contains(name)) {
5858
continue;
5959
}
6060

@@ -65,11 +65,11 @@ private static void loadClassesInJar(File file) throws IOException {
6565
private static void loadClassesInClasspathEntry(String entry) throws IOException {
6666
File file = new File(entry);
6767

68-
if(!file.exists()) {
68+
if (!file.exists()) {
6969
throw new FileNotFoundException("Classpath entry does not exist: " + file.getPath());
7070
}
7171

72-
if(file.isDirectory() || !file.getPath().endsWith(".jar")) {
72+
if (file.isDirectory() || !file.getPath().endsWith(".jar")) {
7373
System.err.println("[WARN] Only jar classpath entries are supported. Skipping " + file.getPath());
7474
return;
7575
}
@@ -79,10 +79,10 @@ private static void loadClassesInClasspathEntry(String entry) throws IOException
7979

8080
private static void loadAllClasses() throws IOException {
8181
final String classPath = System.getProperty("java.class.path");
82-
if(classPath == null) {
82+
if (classPath == null) {
8383
return;
8484
}
85-
for(String classPathEntry : classPath.split(File.pathSeparator)) {
85+
for (String classPathEntry : classPath.split(File.pathSeparator)) {
8686
loadClassesInClasspathEntry(classPathEntry);
8787
}
8888
}

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/EventHandlerLoader.java

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44

55
import com.amazonaws.services.lambda.runtime.ClientContext;
66
import com.amazonaws.services.lambda.runtime.Context;
7+
import com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal;
78
import com.amazonaws.services.lambda.runtime.RequestHandler;
89
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
9-
import com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal;
10-
10+
import com.amazonaws.services.lambda.runtime.api.client.LambdaRequestHandler.UserFaultHandler;
1111
import com.amazonaws.services.lambda.runtime.api.client.api.LambdaClientContext;
1212
import com.amazonaws.services.lambda.runtime.api.client.api.LambdaCognitoIdentity;
1313
import com.amazonaws.services.lambda.runtime.api.client.api.LambdaContext;
14+
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.InvocationRequest;
1415
import com.amazonaws.services.lambda.runtime.api.client.util.UnsafeUtil;
1516
import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer;
1617
import com.amazonaws.services.lambda.runtime.serialization.events.LambdaEventSerializers;
1718
import com.amazonaws.services.lambda.runtime.serialization.factories.GsonFactory;
1819
import com.amazonaws.services.lambda.runtime.serialization.factories.JacksonFactory;
1920
import com.amazonaws.services.lambda.runtime.serialization.util.Functions;
2021
import com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil;
21-
import com.amazonaws.services.lambda.runtime.api.client.LambdaRequestHandler.UserFaultHandler;
22-
import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.InvocationRequest;
2322

2423
import java.io.ByteArrayOutputStream;
2524
import java.io.IOException;
@@ -42,9 +41,7 @@
4241
import java.util.Map;
4342
import java.util.Optional;
4443

45-
import static com.amazonaws.services.lambda.runtime.api.client.UserFault.filterStackTrace;
46-
import static com.amazonaws.services.lambda.runtime.api.client.UserFault.makeUserFault;
47-
import static com.amazonaws.services.lambda.runtime.api.client.UserFault.trace;
44+
import static com.amazonaws.services.lambda.runtime.api.client.UserFault.*;
4845

4946
public final class EventHandlerLoader {
5047
private static final byte[] _JsonNull = new byte[]{'n', 'u', 'l', 'l'};
@@ -57,12 +54,14 @@ private enum Platform {
5754

5855
private static final EnumMap<Platform, Map<Type, PojoSerializer<Object>>> typeCache = new EnumMap<>(Platform.class);
5956

60-
private EventHandlerLoader() { }
57+
private EventHandlerLoader() {
58+
}
6159

6260
/**
6361
* returns the appropriate serializer for the class based on platform and whether the class is a supported event
62+
*
6463
* @param platform enum platform
65-
* @param type Type of object used
64+
* @param type Type of object used
6665
* @return PojoSerializer
6766
* @see Platform for which platforms are used
6867
* @see LambdaEventSerializers for how mixins and modules are added to the serializer
@@ -76,7 +75,7 @@ private static PojoSerializer<Object> getSerializer(Platform platform, Type type
7675

7776
// if serializing a Class that is a Lambda supported event, use Jackson with customizations
7877
if (type instanceof Class) {
79-
Class<Object> clazz = ((Class)type);
78+
Class<Object> clazz = ((Class) type);
8079
if (LambdaEventSerializers.isLambdaSupportedEvent(clazz.getName())) {
8180
return LambdaEventSerializers.serializerFor(clazz, AWSLambda.customerClassLoader);
8281
}
@@ -150,7 +149,7 @@ private static Platform getPlatform(Context context) {
150149
}
151150

152151
private static boolean isVoid(Type type) {
153-
return Void.TYPE.equals(type) || (type instanceof Class) && Void.class.isAssignableFrom((Class<?>)type);
152+
return Void.TYPE.equals(type) || (type instanceof Class) && Void.class.isAssignableFrom((Class<?>) type);
154153
}
155154

156155
/**
@@ -393,7 +392,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
393392
}
394393
}
395394

396-
public static <T> Constructor<T> getConstructor(Class<T> clazz) throws Exception {
395+
private static <T> Constructor<T> getConstructor(Class<T> clazz) throws Exception {
397396
final Constructor<T> constructor;
398397
try {
399398
constructor = clazz.getConstructor();
@@ -409,7 +408,7 @@ public static <T> Constructor<T> getConstructor(Class<T> clazz) throws Exception
409408
return constructor;
410409
}
411410

412-
public static <T> T newInstance(Constructor<? extends T> constructor) {
411+
private static <T> T newInstance(Constructor<? extends T> constructor) {
413412
try {
414413
return constructor.newInstance();
415414
} catch (UserFault e) {
@@ -458,15 +457,15 @@ public ClassContext(ParameterizedType type, ClassContext curContext) {
458457
for (int i = 0; i < types.length; i++) {
459458
Type t = types[i];
460459
if (t instanceof TypeVariable) {
461-
types[i] = curContext.resolveTypeVariable((TypeVariable)t);
460+
types[i] = curContext.resolveTypeVariable((TypeVariable) t);
462461
}
463462
}
464463

465464
Type t = type.getRawType();
466465
if (t instanceof Class) {
467-
this.clazz = (Class)t;
466+
this.clazz = (Class) t;
468467
} else if (t instanceof TypeVariable) {
469-
this.clazz = (Class)((TypeVariable)t).getGenericDeclaration();
468+
this.clazz = (Class) ((TypeVariable) t).getGenericDeclaration();
470469
} else {
471470
throw new RuntimeException("Type " + t + " is of unexpected type " + t.getClass());
472471
}
@@ -499,30 +498,30 @@ private TypeVariable[] getTypeParameters() {
499498
*
500499
* @return null of no type found. Otherwise the type found.
501500
*/
502-
public static Type[] findInterfaceParameters(Class<?> clazz, Class<?> iface) {
501+
private static Type[] findInterfaceParameters(Class<?> clazz, Class<?> iface) {
503502
LinkedList<ClassContext> clazzes = new LinkedList<>();
504-
clazzes.addFirst(new ClassContext(clazz, (Type[])null));
503+
clazzes.addFirst(new ClassContext(clazz, (Type[]) null));
505504
while (!clazzes.isEmpty()) {
506505
final ClassContext curContext = clazzes.removeLast();
507506
Type[] interfaces = curContext.clazz.getGenericInterfaces();
508507

509508
for (Type type : interfaces) {
510509
if (type instanceof ParameterizedType) {
511-
ParameterizedType candidate = (ParameterizedType)type;
510+
ParameterizedType candidate = (ParameterizedType) type;
512511
Type rawType = candidate.getRawType();
513512
if (!(rawType instanceof Class)) {
514513
//should be impossible
515514
System.err.println("raw type is not a class: " + rawType);
516515
continue;
517516
}
518-
Class<?> rawClass = (Class<?>)rawType;
517+
Class<?> rawClass = (Class<?>) rawType;
519518
if (iface.isAssignableFrom(rawClass)) {
520519
return new ClassContext(candidate, curContext).actualTypeArguments;
521520
} else {
522521
clazzes.addFirst(new ClassContext(candidate, curContext));
523522
}
524523
} else if (type instanceof Class) {
525-
clazzes.addFirst(new ClassContext((Class<?>)type, curContext));
524+
clazzes.addFirst(new ClassContext((Class<?>) type, curContext));
526525
} else {
527526
//should never happen?
528527
System.err.println("Unexpected type class " + type.getClass().getName());
@@ -531,17 +530,17 @@ public static Type[] findInterfaceParameters(Class<?> clazz, Class<?> iface) {
531530

532531
final Type superClass = curContext.clazz.getGenericSuperclass();
533532
if (superClass instanceof ParameterizedType) {
534-
clazzes.addFirst(new ClassContext((ParameterizedType)superClass, curContext));
533+
clazzes.addFirst(new ClassContext((ParameterizedType) superClass, curContext));
535534
} else if (superClass != null) {
536-
clazzes.addFirst(new ClassContext((Class<?>)superClass, curContext));
535+
clazzes.addFirst(new ClassContext((Class<?>) superClass, curContext));
537536
}
538537
}
539538
return null;
540539
}
541540

542541

543542
@SuppressWarnings({"rawtypes"})
544-
public static LambdaRequestHandler wrapRequestHandlerClass(final Class<? extends RequestHandler> clazz) {
543+
private static LambdaRequestHandler wrapRequestHandlerClass(final Class<? extends RequestHandler> clazz) {
545544
Type[] ptypes = findInterfaceParameters(clazz, RequestHandler.class);
546545
if (ptypes == null) {
547546
return new UserFaultHandler(makeUserFault("Class "
@@ -555,7 +554,7 @@ public static LambdaRequestHandler wrapRequestHandlerClass(final Class<? extends
555554

556555
for (Type t : ptypes) {
557556
if (t instanceof TypeVariable) {
558-
Type[] bounds = ((TypeVariable)t).getBounds();
557+
Type[] bounds = ((TypeVariable) t).getBounds();
559558
boolean foundBound = false;
560559
if (bounds != null) {
561560
for (Type bound : bounds) {
@@ -588,7 +587,7 @@ public static LambdaRequestHandler wrapRequestHandlerClass(final Class<? extends
588587
}
589588
}
590589

591-
public static LambdaRequestHandler wrapRequestStreamHandlerClass(final Class<? extends RequestStreamHandler> clazz) {
590+
private static LambdaRequestHandler wrapRequestStreamHandlerClass(final Class<? extends RequestStreamHandler> clazz) {
592591
final Constructor<? extends RequestStreamHandler> constructor;
593592
try {
594593
constructor = getConstructor(clazz);
@@ -600,7 +599,7 @@ public static LambdaRequestHandler wrapRequestStreamHandlerClass(final Class<? e
600599
}
601600
}
602601

603-
public static LambdaRequestHandler loadStreamingRequestHandler(Class<?> clazz) {
602+
private static LambdaRequestHandler loadStreamingRequestHandler(Class<?> clazz) {
604603
if (RequestStreamHandler.class.isAssignableFrom(clazz)) {
605604
return wrapRequestStreamHandlerClass(clazz.asSubclass(RequestStreamHandler.class));
606605
} else if (RequestHandler.class.isAssignableFrom(clazz)) {
@@ -730,10 +729,9 @@ private static final boolean lastParameterIsContext(Class<?>[] params) {
730729
public int compare(Method lhs, Method rhs) {
731730

732731
//1. Non bridge methods are preferred over bridge methods.
733-
if (! lhs.isBridge() && rhs.isBridge()) {
732+
if (!lhs.isBridge() && rhs.isBridge()) {
734733
return -1;
735-
}
736-
else if (!rhs.isBridge() && lhs.isBridge()) {
734+
} else if (!rhs.isBridge() && lhs.isBridge()) {
737735
return 1;
738736
}
739737

@@ -828,13 +826,13 @@ private static LambdaRequestHandler loadEventPojoHandler(HandlerInfo handlerInfo
828826
}
829827

830828
@SuppressWarnings({"rawtypes"})
831-
public static LambdaRequestHandler wrapPojoHandler(RequestHandler instance, Type pType, Type rType) {
829+
private static LambdaRequestHandler wrapPojoHandler(RequestHandler instance, Type pType, Type rType) {
832830
return wrapRequestStreamHandler(new PojoHandlerAsStreamHandler(instance, Optional.ofNullable(pType),
833831
isVoid(rType) ? Optional.<Type>empty() : Optional.of(rType)
834832
));
835833
}
836834

837-
public static String exceptionToString(Throwable t) {
835+
private static String exceptionToString(Throwable t) {
838836
StringWriter writer = new StringWriter(65536);
839837
try (PrintWriter wrapped = new PrintWriter(writer)) {
840838
t.printStackTrace(wrapped);
@@ -849,7 +847,7 @@ public static String exceptionToString(Throwable t) {
849847
return buffer.toString();
850848
}
851849

852-
public static LambdaRequestHandler wrapRequestStreamHandler(final RequestStreamHandler handler) {
850+
private static LambdaRequestHandler wrapRequestStreamHandler(final RequestStreamHandler handler) {
853851
return new LambdaRequestHandler() {
854852
private final ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
855853
private Functions.V2<String, String> log4jContextPutMethod = null;
@@ -860,14 +858,15 @@ private void safeAddRequestIdToLog4j(String log4jContextClassName,
860858
Class<?> log4jContextClass = ReflectUtil.loadClass(AWSLambda.customerClassLoader, log4jContextClassName);
861859
log4jContextPutMethod = ReflectUtil.loadStaticV2(log4jContextClass, "put", false, String.class, contextMapValueClass);
862860
log4jContextPutMethod.call("AWSRequestId", request.getId());
863-
} catch (Exception e) {}
861+
} catch (Exception e) {
862+
}
864863
}
865864

866865
public ByteArrayOutputStream call(InvocationRequest request) throws Error, Exception {
867866
output.reset();
868867

869868
LambdaCognitoIdentity cognitoIdentity = null;
870-
if(request.getCognitoIdentity() != null && !request.getCognitoIdentity().isEmpty()) {
869+
if (request.getCognitoIdentity() != null && !request.getCognitoIdentity().isEmpty()) {
871870
cognitoIdentity = getCognitoSerializer().fromJson(request.getCognitoIdentity());
872871
}
873872

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/Failure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Failure(Throwable t) {
3636
this.errorType = t.getClass().getName();
3737
StackTraceElement[] trace = t.getStackTrace();
3838
this.stackTrace = new String[trace.length];
39-
for( int i = 0; i < trace.length; i++) {
39+
for (int i = 0; i < trace.length; i++) {
4040
this.stackTrace[i] = trace[i].toString();
4141
}
4242
Throwable cause = t.getCause();

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/HandlerInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class InvalidHandlerException extends RuntimeException {
1010
public final Class<?> clazz;
1111
public final String methodName;
1212

13-
public HandlerInfo (Class<?> clazz, String methodName) {
13+
public HandlerInfo(Class<?> clazz, String methodName) {
1414
this.clazz = clazz;
1515
this.methodName = methodName;
1616
}
@@ -19,15 +19,15 @@ public static HandlerInfo fromString(String handler, ClassLoader cl) throws Clas
1919
final int colonLoc = handler.lastIndexOf("::");
2020
final String className;
2121
final String methodName;
22-
if(colonLoc < 0) {
22+
if (colonLoc < 0) {
2323
className = handler;
2424
methodName = null;
2525
} else {
2626
className = handler.substring(0, colonLoc);
2727
methodName = handler.substring(colonLoc + 2);
2828
}
2929

30-
if(className.isEmpty() || (methodName != null && methodName.isEmpty())) {
30+
if (className.isEmpty() || (methodName != null && methodName.isEmpty())) {
3131
throw new InvalidHandlerException();
3232
}
3333
return new HandlerInfo(Class.forName(className, true, cl), methodName);

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/LambdaEnvironment.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
import com.amazonaws.services.lambda.runtime.api.client.util.EnvReader;
66

7+
import static com.amazonaws.services.lambda.runtime.api.client.ReservedRuntimeEnvironmentVariables.*;
78
import static java.lang.Integer.parseInt;
89

910
public class LambdaEnvironment {
1011
public static final EnvReader ENV_READER = new EnvReader();
11-
public static final int MEMORY_LIMIT = parseInt(ENV_READER.getEnvOrDefault(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_FUNCTION_MEMORY_SIZE, "128"));
12-
public static final String LOG_GROUP_NAME = ENV_READER.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_LOG_GROUP_NAME);
13-
public static final String LOG_STREAM_NAME = ENV_READER.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_LOG_STREAM_NAME);
14-
public static final String FUNCTION_NAME = ENV_READER.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_FUNCTION_NAME);
15-
public static final String FUNCTION_VERSION = ENV_READER.getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_FUNCTION_VERSION);
12+
public static final int MEMORY_LIMIT = parseInt(ENV_READER.getEnvOrDefault(AWS_LAMBDA_FUNCTION_MEMORY_SIZE, "128"));
13+
public static final String LOG_GROUP_NAME = ENV_READER.getEnv(AWS_LAMBDA_LOG_GROUP_NAME);
14+
public static final String LOG_STREAM_NAME = ENV_READER.getEnv(AWS_LAMBDA_LOG_STREAM_NAME);
15+
public static final String FUNCTION_NAME = ENV_READER.getEnv(AWS_LAMBDA_FUNCTION_NAME);
16+
public static final String FUNCTION_VERSION = ENV_READER.getEnv(AWS_LAMBDA_FUNCTION_VERSION);
1617
}

0 commit comments

Comments
 (0)