[ 
https://issues.apache.org/jira/browse/BEAM-2701?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16173349#comment-16173349
 ] 

ASF GitHub Bot commented on BEAM-2701:
--------------------------------------

GitHub user rmannibucau opened a pull request:

    https://github.com/apache/beam/pull/3871

    [BEAM-2701] ensure objectinputstream uses the right classloader for 
serialization

    When the PTransform are not loaded with the app classloader the 
ensureSerializable code can end up through ObjectInputStream on 
vmLatestUserDefinedClassLoader which likely falls back on app classloader 
whereas it should use the TCCL in resolveClass.
    
    This PR ensures:
    
    1. we use the TCCL as expected to deserialize an instance
    2. uses the serialized instance classloader contextually in 
ensureSerializable to tolerate cross classloader usage

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/rmannibucau/incubator-beam 
fix/serialization-classloader

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/beam/pull/3871.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #3871
    
----
commit 0c3d743f50a8c40fb1f064886996941af37fb8c8
Author: Romain Manni-Bucau <rmannibu...@gmail.com>
Date:   2017-09-20T15:29:53Z

    ensure objectinputstream uses the right classloader for serialization

----


> use a custom implementation of java.io.ObjectInputStream
> --------------------------------------------------------
>
>                 Key: BEAM-2701
>                 URL: https://issues.apache.org/jira/browse/BEAM-2701
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Romain Manni-Bucau
>            Assignee: Luke Cwik
>
> java.io.ObjectInputStream should override resolve[Proxy]Class using the TCCL 
> to support any classloader and not fallback into some JVM pitfall using 
> another classloader (default). This will enable beam to use any classloader 
> instead of requiring to run in the JVM using java serialization.
> {code}
>     @Override
>     protected Class<?> resolveClass(final ObjectStreamClass classDesc) throws 
> IOException, ClassNotFoundException {
>         final String n = classDesc.getName();
>         final ClassLoader classloader = getClassloader();
>         try {
>             return Class.forName(n, false, classloader);
>         } catch (ClassNotFoundException e) {
>             if (n.equals("boolean")) {
>                 return boolean.class;
>             }
>             if (n.equals("byte")) {
>                 return byte.class;
>             }
>             if (n.equals("char")) {
>                 return char.class;
>             }
>             if (n.equals("short")) {
>                 return short.class;
>             }
>             if (n.equals("int")) {
>                 return int.class;
>             }
>             if (n.equals("long")) {
>                 return long.class;
>             }
>             if (n.equals("float")) {
>                 return float.class;
>             }
>             if (n.equals("double")) {
>                 return double.class;
>             }
>             //Last try - Let runtime try and find it.
>             return Class.forName(n, false, null);
>         }
>     }
>     @Override
>     protected Class resolveProxyClass(final String[] interfaces) throws 
> IOException, ClassNotFoundException {
>         final Class[] cinterfaces = new Class[interfaces.length];
>         for (int i = 0; i < interfaces.length; i++) {
>             cinterfaces[i] = getClassloader().loadClass(interfaces[i]);
>         }
>         try {
>             return Proxy.getProxyClass(getClassloader(), cinterfaces);
>         } catch (IllegalArgumentException e) {
>             throw new ClassNotFoundException(null, e);
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to