# HG changeset patch # User coffeys # Date 1431447742 -3600 # Node ID 2e939bf6c09bb180271483bf21e712f152a102ed # Parent c4bc1ce106620bc9e35988ca367e856697fedfb3 8076409: Reinforce RMI framework Reviewed-by: smarks diff -r c4bc1ce10662 -r 2e939bf6c09b src/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java --- a/src/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java Fri Apr 10 16:08:13 2015 +0200 +++ b/src/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java Tue May 12 17:22:22 2015 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,6 +31,7 @@ import java.rmi.Remote; import java.rmi.UnexpectedException; import java.rmi.activation.Activatable; +import java.security.PrivilegedAction; import java.util.Map; import java.util.WeakHashMap; import sun.rmi.server.Util; @@ -56,6 +57,25 @@ { private static final long serialVersionUID = 2L; + // set to true if invocation handler allows finalize method (legacy behavior) + private static final boolean allowFinalizeInvocation; + + static { + final String propName = "sun.rmi.server.invocationhandler.allowFinalizeInvocation"; + String allowProp = java.security.AccessController.doPrivileged( + new PrivilegedAction() { + @Override + public String run() { + return System.getProperty(propName); + } + }); + if ("".equals(allowProp)) { + allowFinalizeInvocation = true; + } else { + allowFinalizeInvocation = Boolean.parseBoolean(allowProp); + } + } + /** * A weak hash map, mapping classes to weak hash maps that map * method objects to method hashes. @@ -144,6 +164,9 @@ { if (method.getDeclaringClass() == Object.class) { return invokeObjectMethod(proxy, method, args); + } else if ("finalize".equals(method.getName()) && method.getParameterTypes().length == 0 && + !allowFinalizeInvocation) { + return null; // ignore } else { return invokeRemoteMethod(proxy, method, args); }