-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not load java.awt.Component and java.beans.Customizer classes when they are not used in Java Beans #5065
Changes from 1 commit
69e3491
ee603e4
a1a4c6e
deed713
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2022, BELLSOFT. All rights reserved. | ||
* Copyright (c) 2022, 2022, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package com.oracle.svm.core.jdk; | ||
|
||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
import com.sun.beans.finder.ClassFinder; | ||
|
||
@SuppressWarnings({"static-method", "unused"}) | ||
public final class JavaBeansSubstitutions { | ||
// Checkstyle: stop | ||
|
||
// Do not make string final to avoid class name interception | ||
// in Class.forName(...) call | ||
private static String COMPONENT_CLASS = "java.awt.Component"; | ||
private static String CUSTOMIZER_CLASS = "java.beans.Customizer"; | ||
|
||
@TargetClass(className = "java.beans.Introspector") | ||
static final class Target_java_beans_Introspector { | ||
|
||
// Do not load java.awt.Component and java.beans.Customizer classes | ||
// when they are not used | ||
@Substitute | ||
private static Class<?> findCustomizerClass(Class<?> type) { | ||
String name = type.getName() + "Customizer"; | ||
try { | ||
type = ClassFinder.findClass(name, type.getClassLoader()); | ||
if (Class.forName(COMPONENT_CLASS).isAssignableFrom(type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot use The proper solution is a reachability handler: when But of course you found a propbably larger pattern where we currently include too much in the image: the problem is actually not that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is the question which is not clear for me. The code in question is:
Is it possible for graal to understand that if a class Foo is passed to findCustomizerClass(...) method then the concatenation the Foo class name with "Customizer" string leads to a class which can't be found by ClassFinder.findClass(...) method (which is actually Or could you give more details about a reachability handler which can help in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For the code in question I see three use cases:
For the first case the application does not use the Component class at all and the behavior of running a program by java or native image gives the same result. For the second case I used BeanSample example:
Java returns
A native image which has been made without an additional configuration returns null customizer:
This is because the BeanClassCustomizer is only created by reflection.
Now the
For the third case where the bean customizer does not extend Component class I used the BeanSample:
Java returns null bean customizer:
The native image with reflection config file returns null customizer as well:
As I see, for all three cases the result which is returned by For the fist case the Component class is not used at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that in the next release we plan to throw special runtime exceptions for missing metadata, so the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fix is updated to use the reachability handler for Two classes
|
||
&& Class.forName(CUSTOMIZER_CLASS).isAssignableFrom(type)) { | ||
return type; | ||
} | ||
} catch (Exception exception) { | ||
// ignore any exceptions | ||
} | ||
return null; | ||
} | ||
} | ||
// Checkstyle: resume | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a doc comment.