Skip to content
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

How to reduce the amount of metadata when there are a lot of reflections in the code. #232

Closed
wangliang181230 opened this issue Feb 15, 2023 · 4 comments
Labels
question Further information is requested

Comments

@wangliang181230
Copy link

wangliang181230 commented Feb 15, 2023

Describe the problem
See a class:

public class ClassAlias {

    private static final Map<String, Class<?>> CLASS_ALIAS = new HashMap<>();

    static {
        addAlias("class1", Class.forName("Class1")); // in the `native-image`, throw `ClassNotFoundException`.
        addAlias("class2", Class.forName("Class2"));
        addAlias("class3", Class.forName("Class3"));
        addAlias("class4", Class4.class); // in the `native-image`, the clazz will be a null value.
        addAlias("class5", Class5.class);
        addAlias("class6", Class6.class);
        ......
        addAlias("class99", Class.forName("Class99"));
        addAlias("class100", Class100.class);
    }

    public static void addAlias(String alias, Class<?> clazz) {
        CLASS_ALIAS.add(alias, clazz);
    }

}

Please see a specific class: https://github.com/x-stream/xstream/blob/master/xstream/src/java/com/thoughtworks/xstream/XStream.java

Can I only add 100 metadata? Or are there other simpler configurations?

Additional context
Add any other context about the problem here.

System Info (please complete the following information):

  • OS: [e.g. Windows]
  • GraalVM Version [e.g. 22.0 CE]
  • Java Version [e.g. 17]
  • Plugin version [e.g. native-gradle-plugin:0.9.10]

To Reproduce
If possible please attach a complete reproducer here (either as a zip file or as a link to public repository/branch).

@wangliang181230 wangliang181230 added the question Further information is requested label Feb 15, 2023
@vjovanov
Copy link
Member

We are working towards a way to do this kind of definition in the code of the project. This is expected to land in the next release of GraalVM as a preview feature. Until then, we can only do this via JSON.

@wangliang181230
Copy link
Author

OK, I understand.
Thank you for your answer.
Look forward to the next release.

@dnestoro dnestoro closed this as completed Nov 2, 2023
@wangliang181230
Copy link
Author

@vjovanov @dnestoro Is there a new feature?

@vjovanov
Copy link
Member

Yes, the example above should already work with Native Image. When forName gets a literal it should be converted directly into a class. If that is not the case please open a ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants