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

Reflect.compile(name,content) import static org.joor.Reflect.* gives compilation error, and import org.joor.Reflect that the compiler tells me to use throw exception #91

Closed
michaelm43 opened this issue Jan 17, 2020 · 9 comments

Comments

@michaelm43
Copy link

michaelm43 commented Jan 17, 2020

Expected behavior and actual behavior:

print hellow world to console

Steps to reproduce the problem:

I follower your instructions, added Dependency and imported static org.joor.Reflect.*, but I got a compilation error.
so I used the suggestion eclipse gave me to import org.joor.Reflect.
compile method didn't excised so I changed the dependency version to 0.9.12, and I run my code.

Versions:

0.9.12

  • jOOR:
  • Java:

Error message:

Exception in thread "Thread-1" org.joor.ReflectException: Error while compiling com.example.HelloWorld
at org.joor.Compile.compile(Compile.java:156)
at org.joor.Reflect.compile(Reflect.java:102)
at org.joor.Reflect.compile(Reflect.java:77)
at server.Server.compileFile(Server.java:397)
at server.OurThreadClass.handleRequest(OurThreadClass.java:215)
at server.OurThreadClass.handleConnection(OurThreadClass.java:111)
at server.OurThreadClass.run(OurThreadClass.java:72)
Caused by: java.lang.NullPointerException
at org.joor.Compile.compile(Compile.java:64)
... 6 more

@michaelm43 michaelm43 changed the title Reflect.compile(name,content) has errors. Reflect.compile(name,content) import static org.joor.Reflect.* gives compilation error, and import org.joor.Reflect that the compiler tells me to use throw exception Jan 17, 2020
@lukaseder lukaseder added this to the Version 0.9.13 milestone Jan 17, 2020
@lukaseder
Copy link
Member

Thanks for your report. Can you please provide a complete example including your own source code that helps reproduce this problem?

@michaelm43
Copy link
Author

I tried to use my own input for the Reflect.compile() but I got an error so I used your input (the one you were providing in the git) but still got the same error. I can send you my all code if needed.

	Supplier<String> supplier = Reflect.compile(
		    "com.example.HelloWorld",
		    "package com.example;\n" +
		    "class HelloWorld implements java.util.function.Supplier<String> {\n" +
		    "    public String get() {\n" +
		    "        return \"Hello World!\";\n" +
		    "    }\n" +
		    "}\n").create().get();
	return supplier.get();

This is the import I'm using: import org.joor.Reflect;
Because as I said the import static org.joor.Reflect.*; give me compilation error (Reflect cannot be resolved) and give me Import 'Reflect' (org.joor) solution.

@lukaseder
Copy link
Member

I'm not sure if I understand it. The code example you've shown does not import Reflect.*, nor would you need that import. Also, the stack trace you've shown shows that the compilation actually ran, but failed.

I'll try reproducing this, but I'm still curious why you'd say that this has anything to do with your static import...

@michaelm43
Copy link
Author

I'm not sure as well whats going on. Its my first time trying to use a static import. so maybe your code actually fine and I just dont understand what I should do with that.
In general I tried to follow your manual to make your code work. Im calling your code from a non- static method in a non- static class. maybe that was the reason for the code throw exception.

So, I used your import but is says I have compilation error on the Reflect, and tells me I should use another import. If I use your static import I will have a compilation error but when I use the other import I have an error (NullPointerException).
Im sending in the compile method exactly what you gave in your example and I entered into your code to see maybe the example is in correct but it should work.

if you want I can send you the link to my project on git and you will take a look if it helps.
and by the way thank you so much for your time working on this amazing solution!

@lukaseder
Copy link
Member

if you want I can send you the link to my project on git and you will take a look if it helps.
and by the way thank you so much for your time working on this amazing solution!

Code always beats prose, so yes please :)

Or even better, if possible, you could fork this project, add a unit test that reproduces the problem, and send a PR with the failing test.

In any case, think about it this way. If I can reproduce the problem on my machine, then I will be able to fix it right away. If I cannot reproduce this, I cannot really help you very well.

@lukaseder
Copy link
Member

This is a different problem, but I cannot reproduce it either.

NoSuchMethodError means that you were able to compile your code, but at runtime, the jOOR library was not found, or you had a different jOOR library version at runtime than at compile time.

I'm closing this issue as it does not seem to describe any problems in jOOR, but rather general Java classpath setup problems.

@ganatrajay
Copy link

HI ,

i am facing the same issue , can you help me out for android ?

thank you

@lukaseder
Copy link
Member

@ganatrajay Thanks for your message. Can you please open a new issue with details on how to reproduce your problem?

@lukaseder
Copy link
Member

@ganatrajay I'm sorry, I overlooked you were using android. See my answer here: #102 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants