Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/incubator-flink/pull/269#discussion_r21900493
  
    --- Diff: 
flink-java/src/main/java/org/apache/flink/api/java/ClosureCleaner.java ---
    @@ -0,0 +1,131 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.api.java;
    +
    +
    +import org.apache.flink.api.common.InvalidProgramException;
    +import org.apache.flink.util.InstantiationUtil;
    +import org.objectweb.asm.ClassReader;
    +import org.objectweb.asm.ClassVisitor;
    +import org.objectweb.asm.MethodVisitor;
    +import org.objectweb.asm.Opcodes;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.IOException;
    +import java.lang.reflect.Field;
    +
    +public class ClosureCleaner {
    +   private static Logger LOG = 
LoggerFactory.getLogger(ClosureCleaner.class);
    +
    +   private static ClassReader getClassReader(Class<?> cls) {
    +           String className = cls.getName().replaceFirst("^.*\\.", "") + 
".class";
    +           try {
    +                   return new 
ClassReader(cls.getResourceAsStream(className));
    +           } catch (IOException e) {
    +                   throw new RuntimeException("Could not create 
ClassReader: " + e);
    +           }
    +   }
    +
    +   public static void clean(Object func, boolean checkSerializable) {
    +           Class<?> cls = func.getClass();
    +
    +           String this0Name = null;
    +
    +           // First find the field name of the "this$0" field, this can
    +           // be "field$x" depending on the nesting
    +           for (Field f: cls.getDeclaredFields()) {
    +                   if (f.getName().startsWith("this$")) {
    +                           // found our field:
    +                           this0Name = f.getName();
    --- End diff --
    
    It could be that only one field of the pattern is allowed. Just to be on 
the safe side, I'm changing it to check all fields of the pattern "this$*".


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to