Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JavaIoFileSystemAccess - null pointer
JavaIoFileSystemAccess - null pointer [message #1014000] Sun, 24 February 2013 23:53 Go to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Hi,

the following

public static void main(String[] args) {
        JavaIoFileSystemAccess fileWriter = new JavaIoFileSystemAccess();
        fileWriter.setOutputPath("out");
        fileWriter.generateFile("bla", "content");
        return;
}


raises a NullPointerException.
After looking into the code, I see the problem is that two members of the class JavaIoFileSystemAccess are never initialized. The constructor with no args does nothing. There are no setters.

My project depends on the jar org.eclipse.xtext_2.2.1... .jar , which is stored on my filesystem.
However my Eclipse (Juno) has version 2.3.1 of xtext

When I ctrl+click on JavaIoFileSystemAccess in my code it opens the class file, saying that there is no source attached. But when I click in the console on the error message of the exception, it magically opens a source file, which I think is the one installed in eclipse.

How am I supposed to use JavaIoFileSystemAccess?
Do you think I am having a version conflict problem?

Thanks in advance
B.
Re: JavaIoFileSystemAccess - null pointer [message #1014098 is a reply to message #1014000] Mon, 25 February 2013 06:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i think you should use google guice to create your instance

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JavaIoFileSystemAccess - null pointer [message #1014122 is a reply to message #1014098] Mon, 25 February 2013 07:48 Go to previous messageGo to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Quote:

i think you should use google guice to create your instance


How? The @Inject tag before the JavaIoFileSystemAccess did not work.
Should I create some sort of injector and then call 'getInstance' ?
How should I create such injector?

However my code somehow resumed, and it works again as it always did, without injector and using only the no-args constructor Shocked

Any idea about the issue of the source file? (no source attached to class when ctrl+click on the class name in my .java, while clicking on the same class in an exception message in the console leads to the actual source code)

Thanks again
B
Re: JavaIoFileSystemAccess - null pointer [message #1053364 is a reply to message #1014122] Sat, 04 May 2013 15:46 Go to previous messageGo to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
I'm still having the same problem Sad

Null pointer exception in JavaIoFileSystemAccess.getEncoding()

I'm sure the problem is that with the xtext-jars version 2.3.1 you have to use injection to create an instance, while with version 2.2.1 the no-arg constructor is perfectly fine.

My project depends on an external jar that happens to be the 2.2.1, but for some reason at runtime Eclipse resolves libraries dependencies with the 2.3.1, which leads to an exception (since in my code I am using the no-arg constructor of JavaIoFileSystemAccess).

Any idea on how to solve it?
By the way, how do I know the full path of an opened file in Eclipse??? When I click on the exception message, eclipse opens the source code attached to the .class of JavaIoFileSystemAccess, but I have no way of determining where such a .class is, to demonstrate that Eclipse is picking the wrong file (2.3.1 instead of 2.2.1)

thanks a lot
Re: JavaIoFileSystemAccess - null pointer [message #1053366 is a reply to message #1053364] Sat, 04 May 2013 16:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

are you sure you create the access with guice? and what does that has todo with Xtext version?
the class is contained in the org.eclipse.xtext-xxxxjar.

i have no idea what you do in your classloading.
i have no idea how you use the JavaIoFileSystemAccess, where you use it aso.
so a bit more of context of what you are exactly doing
(example code) would help


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JavaIoFileSystemAccess - null pointer [message #1053367 is a reply to message #1053366] Sat, 04 May 2013 16:26 Go to previous messageGo to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Thanks for the reply

No, I am NOT using guice.
I don't want to do it, it is not necessary with org.eclipse.xtext_2.2.1... .jar (I never used guice for JavaIoFileSystemAccess before, and it always worked)

As I said, a trivial code such as this
public static void main(String[] args) {
        JavaIoFileSystemAccess fileWriter = new JavaIoFileSystemAccess();
        fileWriter.setOutputPath("out");
        fileWriter.generateFile("bla", "content");
        return;
}


reproduces the problem, i.e. raises the null pointer exception

The classpath of my project is very simple, it includes some external jars, including org.eclipse.xtext_2.2.1... .jar
The project (let me call it 'P') is a regular java project, where i want to use the code generator of a DSL of mine; therefore the project depends on some xtext jars. It also has a dependency on my DSL project (a "project reference" in Eclipse)

I have the feeling that Eclipse is "linking" my project with org.eclipse.xtext_2.3.1... .jar even though the classpath is configured with the version 2.2.1 of the jar

Maybe the problem is that the DSL project is actually using the 2.3.1 jars (this is the default "plugin dependencies", in the project properties), so maybe it overrides the classpath of 'P'.

Hope this gives you a little bit more of context info
Re: JavaIoFileSystemAccess - null pointer [message #1053369 is a reply to message #1053367] Sat, 04 May 2013 16:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

why dont simply set the ecoding provider manually in this case?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JavaIoFileSystemAccess - null pointer [message #1053372 is a reply to message #1053369] Sat, 04 May 2013 16:43 Go to previous messageGo to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Hi,

because that gives a compilation error Sad

In the 2.2.1 version there is no constructor argument nor setter method for the encoding provider.

If I try to set it I have a compilation problem, and if I try to run it anyway I have the exception about "unresolved compilation error"

Quite annoying: at compile time Eclipse looks at the 2.2.1 jar, at runtime it picks the 2.3.1 ... (if my intuition is correct)

I guess the only way to solve my problem is to update my external jars to version 2.3.1 (however this seems quite a general issue with Eclipse)

thanks
Re: JavaIoFileSystemAccess - null pointer [message #1053374 is a reply to message #1053372] Sat, 04 May 2013 16:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i dont know your project/eclipse/build setup so hard to tell.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JavaIoFileSystemAccess - null pointer [message #1053385 is a reply to message #1053374] Sat, 04 May 2013 19:43 Go to previous messageGo to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Hello,

Eclipse Juno service release 1
Xtext SDK 2.3.1.v201208210947

My project is a regular Java project created within Eclipse.
I only did some configuration in 'properties - java build path', where I set my DSL project as a "required project on the build path", and the various xtext jars (2.2.1) as libraries, added with "add external jar"
Re: JavaIoFileSystemAccess - null pointer [message #1053387 is a reply to message #1053385] Sat, 04 May 2013 21:48 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hmmmm then i dont understand your problem. can you share the project.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How I can get the contents of my DSL file
Next Topic:Take an integer typed in the DSL and generate a java variable with it
Goto Forum:
  


Current Time: Fri Mar 29 02:09:25 GMT 2024

Powered by FUDForum. Page generated in 0.02920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top