Skip to content

Commit 8624c29

Browse files
dawidwyszentol
authored andcommitted
[FLINK-7190] [java] Activate checkstyle flink-java/*
This closes apache#4343.
1 parent 87a1984 commit 8624c29

21 files changed

+897
-819
lines changed

flink-java/src/main/java/org/apache/flink/api/java/ClosureCleaner.java

+20-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.objectweb.asm.ClassVisitor;
2727
import org.objectweb.asm.MethodVisitor;
2828
import org.objectweb.asm.Opcodes;
29-
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
3231

@@ -41,53 +40,52 @@
4140
*/
4241
@Internal
4342
public class ClosureCleaner {
44-
45-
private static Logger LOG = LoggerFactory.getLogger(ClosureCleaner.class);
46-
43+
44+
private static final Logger LOG = LoggerFactory.getLogger(ClosureCleaner.class);
45+
4746
/**
4847
* Tries to clean the closure of the given object, if the object is a non-static inner
4948
* class.
50-
*
49+
*
5150
* @param func The object whose closure should be cleaned.
5251
* @param checkSerializable Flag to indicate whether serializability should be checked after
5352
* the closure cleaning attempt.
54-
*
53+
*
5554
* @throws InvalidProgramException Thrown, if 'checkSerializable' is true, and the object was
5655
* not serializable after the closure cleaning.
57-
*
56+
*
5857
* @throws RuntimeException A RuntimeException may be thrown, if the code of the class could not
5958
* be loaded, in order to process during teh closure cleaning.
6059
*/
6160
public static void clean(Object func, boolean checkSerializable) {
6261
if (func == null) {
6362
return;
6463
}
65-
64+
6665
final Class<?> cls = func.getClass();
6766

6867
// First find the field name of the "this$0" field, this can
6968
// be "this$x" depending on the nesting
7069
boolean closureAccessed = false;
71-
70+
7271
for (Field f: cls.getDeclaredFields()) {
7372
if (f.getName().startsWith("this$")) {
7473
// found a closure referencing field - now try to clean
7574
closureAccessed |= cleanThis0(func, cls, f.getName());
7675
}
7776
}
78-
77+
7978
if (checkSerializable) {
8079
try {
8180
InstantiationUtil.serializeObject(func);
8281
}
8382
catch (Exception e) {
8483
String functionType = getSuperClassOrInterfaceName(func.getClass());
85-
84+
8685
String msg = functionType == null ?
8786
(func + " is not serializable.") :
8887
("The implementation of the " + functionType + " is not serializable.");
89-
90-
88+
9189
if (closureAccessed) {
9290
msg += " The implementation accesses fields of its enclosing class, which is " +
9391
"a common reason for non-serializability. " +
@@ -96,7 +94,7 @@ public static void clean(Object func, boolean checkSerializable) {
9694
} else {
9795
msg += " The object probably contains or references non serializable fields.";
9896
}
99-
97+
10098
throw new InvalidProgramException(msg, e);
10199
}
102100
}
@@ -109,14 +107,14 @@ public static void ensureSerializable(Object obj) {
109107
throw new InvalidProgramException("Object " + obj + " is not serializable", e);
110108
}
111109
}
112-
110+
113111
private static boolean cleanThis0(Object func, Class<?> cls, String this0Name) {
114-
112+
115113
This0AccessFinder this0Finder = new This0AccessFinder(this0Name);
116114
getClassReader(cls).accept(this0Finder, 0);
117-
115+
118116
final boolean accessesClosure = this0Finder.isThis0Accessed();
119-
117+
120118
if (LOG.isDebugEnabled()) {
121119
LOG.debug(this0Name + " is accessed: " + accessesClosure);
122120
}
@@ -129,7 +127,7 @@ private static boolean cleanThis0(Object func, Class<?> cls, String this0Name) {
129127
// has no this$0, just return
130128
throw new RuntimeException("Could not set " + this0Name + ": " + e);
131129
}
132-
130+
133131
try {
134132
this0.setAccessible(true);
135133
this0.set(func, null);
@@ -139,10 +137,10 @@ private static boolean cleanThis0(Object func, Class<?> cls, String this0Name) {
139137
throw new RuntimeException("Could not set " + this0Name + " to null. " + e.getMessage(), e);
140138
}
141139
}
142-
140+
143141
return accessesClosure;
144142
}
145-
143+
146144
private static ClassReader getClassReader(Class<?> cls) {
147145
String className = cls.getName().replaceFirst("^.*\\.", "") + ".class";
148146
try {
@@ -151,8 +149,7 @@ private static ClassReader getClassReader(Class<?> cls) {
151149
throw new RuntimeException("Could not create ClassReader: " + e.getMessage(), e);
152150
}
153151
}
154-
155-
152+
156153
private static String getSuperClassOrInterfaceName(Class<?> cls) {
157154
Class<?> superclass = cls.getSuperclass();
158155
if (superclass.getName().startsWith("org.apache.flink")) {
@@ -176,7 +173,6 @@ class This0AccessFinder extends ClassVisitor {
176173

177174
private final String this0Name;
178175
private boolean isThis0Accessed;
179-
180176

181177
public This0AccessFinder(String this0Name) {
182178
super(Opcodes.ASM5);

flink-java/src/main/java/org/apache/flink/api/java/CollectionEnvironment.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import org.apache.flink.api.common.Plan;
2424
import org.apache.flink.api.common.operators.CollectionExecutor;
2525

26+
/**
27+
* Version of {@link ExecutionEnvironment} that allows serial, local, collection-based executions of Flink programs.
28+
*/
2629
@PublicEvolving
2730
public class CollectionEnvironment extends ExecutionEnvironment {
2831

@@ -40,7 +43,7 @@ public JobExecutionResult execute(String jobName) throws Exception {
4043
public int getParallelism() {
4144
return 1; // always serial
4245
}
43-
46+
4447
@Override
4548
public String getExecutionPlan() throws Exception {
4649
throw new UnsupportedOperationException("Execution plans are not used for collection-based execution.");

0 commit comments

Comments
 (0)