This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 184503 - Exceptions during source code scanning/parsing
Summary: Exceptions during source code scanning/parsing
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-19 23:30 UTC by jessholle
Modified: 2010-04-23 06:22 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 373719


Attachments
Two new exceptions occurring during code scanning/parsing (8.50 KB, text/plain)
2010-04-19 23:30 UTC, jessholle
Details
NetBeans log file showing exceptions during annotation processing (77.19 KB, application/zip)
2010-04-22 14:03 UTC, jessholle
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jessholle 2010-04-19 23:30:35 UTC
Created attachment 97677 [details]
Two new exceptions occurring during code scanning/parsing

I started the 6.9 daily targeting many free-form projects for which I generated "processpath" information pointing NetBeans to our custom annotation processor.

I receive numerous exceptions of the forms in the attached file.  Our annotation processor works fine from Ant -- including when Ant is invoked from within NetBeans.
Comment 1 Jesse Glick 2010-04-19 23:41:41 UTC
Are you perchance passing backslashes (\) to JSR 269 methods expecting resource paths? Because a resource path must always be /-separated regardless of operating system.
Comment 2 jessholle 2010-04-19 23:56:16 UTC
In the case of the first exception, yes, we are passing literally "wt\fc\_NetFactor" as name to

JavaFileObject f = env.getFiler().createSourceFile(name);

and later calling

openWriter() on f.

So we're only supposed to be using forward-slashes? It's curious that neither javac nor the Eclipse compiler complain -- and NetBeans isn't very clear about what it dislikes here.

I'll get that changed and see if that resolves the issue.
Comment 3 Tomas Zezula 2010-04-20 08:07:10 UTC
From JavaFileManager javadoc:

getFileForInput(SOURCE_PATH, "com.sun.tools.javac", "resources/compiler.properties");

If the call was executed on Windows, with SOURCE_PATH set to "C:\Documents and Settings\UncleBob\src\share\classes" a valid result would be a file object representing the file "C:\Documents and Settings\UncleBob\src\share\classes\com\sun\tools\javac\resources\compiler.properties"
Comment 4 Tomas Zezula 2010-04-20 08:59:47 UTC
Please let me know if fixing the separators solved also the NPE.
Thanks
Comment 5 jessholle 2010-04-20 11:31:06 UTC
Sorry, I was mistaken.

We are calling:

JavaFileObject f = env.getFiler().createSourceFile(name);

but name is of the form "wt.fc._NetFactor" (as per the Javadoc for this API) in the case in question at least when we run our annotation processor from Ant.  This is built up from TypeElement APIs, so something is loused up in NetBeans here in any case, either the TypeElement APIs or the JavaFileObject handling.
Comment 6 Tomas Zezula 2010-04-20 11:45:49 UTC
The  "wt.fc._NetFactor" is a valid parameter to Filer.createSourceFile. Are you sure that you don't pass such a name to createResource or getResource where it's not valid?
I will add logging into FMs.
Comment 7 jessholle 2010-04-20 11:49:27 UTC
The exception is consistently arising from com.sun.tools.javac.processing.JavacFiler$FilerOutputFileObject.openWriter(JavacFiler.java:131) on the JavaFileObject resulting from Filer.createSourceFile().
Comment 8 jessholle 2010-04-20 11:57:13 UTC
I added some debug output to our annotation processor and, yes, we are definitely passing "." delimited names to Filer.createSourceFile() in the NetBeans case, so somehow the JavaFileObject implementation in NetBeans is producing backslashes from this and tripping up.
Comment 9 Tomas Zezula 2010-04-20 11:58:06 UTC
OK, thanks. I will try to get some Win box and try it.
Comment 10 jessholle 2010-04-20 11:59:03 UTC
This is exception report #373719.
Comment 11 Tomas Zezula 2010-04-20 16:34:12 UTC
Now I am able to reproduce it on Windows with my test processor.
Comment 12 Tomas Zezula 2010-04-20 17:06:52 UTC
The java.lang.IllegalArgumentException fixed.
Fixed jet-main e9ae2362b373
Comment 13 Tomas Zezula 2010-04-20 17:08:42 UTC
If the second exception happens even after the fix of this first one please report it as a new issue or reopen this one, I will create a new issue for it. Thanks
Fixed jet-main e9ae2362b373
Comment 14 Jesse Glick 2010-04-20 18:28:41 UTC
(In reply to comment #12)
> jet-main e9ae2362b373

BTW the

  if (File.separatorChar != '/')

guard is unnecessary as s.replace(c,c) == s, so could be simply

  return getRelativePath(new File(root.toURI()), new File(fo.toURI())).
    replace(File.separatorChar, '/');
Comment 15 Tomas Zezula 2010-04-21 09:52:03 UTC
The check is done to prevent O(n) traverse through the string in replace when it's not needed.
Comment 16 Quality Engineering 2010-04-22 04:30:15 UTC
Integrated into 'main-golden', will be available in build *201004220200* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/e9ae2362b373
User: Tomas Zezula <tzezula@netbeans.org>
Log: #184503:Exceptions during source code scanning/parsing
Comment 17 jessholle 2010-04-22 13:45:51 UTC
I tried the fix -- and it resolved the IllegalArgumentException, but not the NullPointerException.

I tried to use the Exception Reporter to send the log, etc, but the current nightly has issues here -- attempts to report exceptions raise other exceptions.

I'll attach a from the 201004220200 nightly.
Comment 18 jessholle 2010-04-22 14:03:54 UTC
Created attachment 97862 [details]
NetBeans log file showing exceptions during annotation processing

A few notes on the NetBeans log I am attaching are in order.

First off, the "Annotation processing generation COMPLETE..." and "Annotation processing round..." message are from our annotation processor and can be ignored.

Secondly, there are actually 3 distinct exceptions in this log:
1) A NullPointerException in com.sun.tools.javac.main.JavaCompiler.processAnnotations().
2) An java.lang.UnsupportedOperationException (No apt root for source root: null) in org.netbeans.modules.java.source.parsing.AptSourceFileManager.getJavaFileForOutput()
3) A java.lang.NullPointerException in org.netbeans.modules.exceptions.ReportPanel.initComponents().

The last of these is clearly an issue with the Exception Reporter functionality and is distinct from the other issues.

I get the impression from the first two exceptions that the generated source tree root (ala -s in javac) may not have been initialized, but that's just a guess.  We pass -s to javac, of course, but there is currently no means to specify such a directory via free-form projects (and I thus I can only assume an internal temporary directory is used or some such).
Comment 19 Tomas Zezula 2010-04-22 14:24:23 UTC
It's better not to mix two excpetions in the single issue. I will create a new one for the NPE.
The new issue is #184734.
Comment 20 Jesse Glick 2010-04-22 16:43:48 UTC
(In reply to comment #15)
> The check is done to prevent O(n) traverse through the string in replace when
> it's not needed.

If it's not needed, there is no traversal of the source string at all - check String.replace source.
Comment 21 Tomas Zezula 2010-04-23 06:22:53 UTC
Right, the String.replace has the same guard.
if (oldChar != newChar) {...}