konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.55k stars 262 forks source link

loadClass signatures missing from ClassLoader #774

Open ldubost opened 9 months ago

ldubost commented 9 months ago

The following signatures are missing from ClassLoader implementation:

public Class<?> loadClass(String name); public Class<?> loadClass(String name, boolean result);

konsoletyper commented 9 months ago

I believe, they should not be supported at all.

ldubost commented 9 months ago

The reason I added them, is that a library was making use of this (probably to load some optional extension), and this breaks the code I've been trying to run at compile time, while at runtime there are not issues. Having the two functions that return null would help in that case supporting more libraries. Now I understand that you might want to keep the classlib only for actually implemented code.

konsoletyper commented 9 months ago

Now I understand that you might want to keep the classlib only for actually implemented code.

Sure. Because for someone it's would not be that "while at runtime there are not issues". In general, it would be strange that TeaVM claims support of certain function and does not produce error when developer uses them, but then behave improperly at run time. So, since it's an issue on your side, you can:

  1. Write a plugin
  2. Use platform marker annotations
  3. If it's entire missing class, you can put it into your project using same naming scheme, TeaVM will pick it
konsoletyper commented 8 months ago

I think ClassLoader.loadClass can be implemented just like Class.forName is implemented. Also, optimization for loadClass("constantString") can be added just like there's one for Class.forName.