PsiFile.getText() throws NPE in #5131

Am I doing something wrong, or is this a bug:

assert value != null;
final XPathFile xpathFile = (XPathFile)myElementFactory.createFileFromText("Dummy.xpath",
XPathFileType.XPATH, value);
String text = xpathFile.getText(); // throws NPE @ PsiFileImpl.java:118

".xpath" is not a registered filetype, if that matters.

Sascha

3 comments

Hi Sascha!
Looks like we don't know how to create this PSI file :). File type
contains not enough information to create one and we need at least
language with not null parser definition. Is your filetype instance of
LanguageFileType? Actually it'd be better if you send me your code.

Thanks,
IK

Sascha Weinreuter wrote:

Am I doing something wrong, or is this a bug:

assert value != null;
final XPathFile xpathFile =
(XPathFile)myElementFactory.createFileFromText("Dummy.xpath",
XPathFileType.XPATH, value);
String text = xpathFile.getText(); // throws NPE @ PsiFileImpl.java:118

".xpath" is not a registered filetype, if that matters.

Sascha

0

Hello Igor,

yes, the passed filetype is a LanguageFileType and Language and ParserDefinition
are definitely present. In 5.1 it was possible to create PsiFiles using
XPathFileType.XPATH.getLanguage().getParserDefinition().createFile(project,
"Dummy.xpath", text);

Now that ParserDefinition.createFile() just takes the new FileViewProvider
interface, the only way I see to do the same is using PsiElementFactory because
I don't think I should implement this interface myself.

I don't have the ported code right here, but I'll investigate this further
tonight and will send you some example code when I still can't figure out what
the problem is.

Thanks,
Sascha

0

Hello Igor,

I managed to find the problem, it's indeed the fact that the filetype is not registered
via FileTypeManager.registerFileType(...). After registering it, the NPE is gone, but I'd
like to have the old behavior back that didn't require this. I created IDEA-6646 about
this issue.

Sascha

0

Please sign in to leave a comment.