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 83308 - ResourceImpl.getSourceText() throws NPE for source file created in default package
Summary: ResourceImpl.getSourceText() throws NPE for source file created in default pa...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks: 78508 78520 78530 82293
  Show dependency tree
 
Reported: 2006-08-23 19:01 UTC by Craig Conover
Modified: 2007-09-26 09:14 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
source to simulate interactions with java model api (2.49 KB, application/octet-stream)
2006-09-06 06:27 UTC, Yang Su
Details
patch, use when you want to test on different branches (6.45 KB, application/octet-stream)
2006-09-06 15:09 UTC, Pavel Flaska
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Conover 2006-08-23 19:01:03 UTC
The javacore module throws exceptions when performing some actions in the UML
module. These exceptions do not happen when the UML elements (and Java source
counterparts) are in a named package. We are aware that JDK doesn't support some
behavior from or within the default package, but we need some sort of workaround
or fix for this so that it does result in exceptions.

If there is something we can do on our end to prevent it, we are happy to do so.
See the issues blocking this issue for UML reproduction scenarios.
Comment 1 Jan Becicka 2006-08-24 11:07:28 UTC
This report is not complete. 

Please follow http://qa.netbeans.org/bugzilla/rules.html




Comment 2 Yang Su 2006-08-25 22:36:30 UTC
The common case in those dependent issues is that UML calls API
JavaClass.getContents.add(Object innerClass);

Both outer and inner classes are in default package, but the outer class source
was not updated, that's the perceived issue.

The root cause is at Java model processing source text for elements in default
package. It seems to expect a first token "package", while in default pakcage
case, it throws below NPE when getSourceText() is invoked.


======================================
java.lang.NullPointerException
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.IndentUtil.getGarbage(IndentUtil.java:286)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.IndentUtil.printHeadGarbage(IndentUtil.java:281)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.IndentUtil.reformatHeadGarbage(IndentUtil.java:325)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.FeatureImpl.generateNewModifiers(FeatureImpl.java:467)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.JavaClassImpl.getRawText(JavaClassImpl.java:802)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.getSourceText(MetadataElement.java:728)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.getSourceText(ResourceImpl.java:1256)
Comment 3 Yang Su 2006-08-29 06:40:35 UTC
change summary and remove "incomplete" keyword
Comment 4 Pavel Flaska 2006-09-04 08:24:36 UTC
I did not find any way how to reproduce it in IDE manually, I will create a test
which will reproduce the issue.
Comment 5 Pavel Flaska 2006-09-04 09:21:46 UTC
I have created a test which tries to reproduce it, but I haven't got any exception.

My usecase:
- having two classes in default package A and B,
- got a B class and added to A.getContents().add(B).

class was successfuly moved to A.

But your comment seems to be correct, do you have any idea what is different in
my and your usecase?
(Tested on current trunk build.)
Comment 6 Yang Su 2006-09-06 06:18:44 UTC
I developed a small test case ( a NB module, source is attached ) to simulate
UML module interaction with Java Model API, I can reproduce the issue on NB 5.0,
5.5 and 6.0 latest qbuild(200608141200).

The difference between your use case and ours is that we set class modifier to
the inner class (B) before calling A.getContents().add(B), the NPE was caught in
ExclusiveMutex.leave(boolean fail) which results in cancellation of planned
changes to the source.

If I manually manipulate the java source to add package statement ( the source
is still in default package ), the NPE is gone and class B will be added to A as
an inner class.

Please delete two test java sources and recreate them each time you test the
case to avoid some cache problems I encountered.

If you still cannot reproduce with provided test case and would like to debug
through uml code, please follow build instructions on 
http://nbbuild.netbeans.org/entpack/build_ep55.html

look for NBEventProcessor.moveInnerClass()

Comment 7 Yang Su 2006-09-06 06:27:41 UTC
Created attachment 33627 [details]
source to simulate interactions with java model api
Comment 8 Pavel Flaska 2006-09-06 13:29:04 UTC
Thanks for the class. It is the same as my testcase, I didn't test it correctly,
I thought the exception will be visible in the log file... Now, I'm able to
reproduce it, so I will provide fix soon.
Comment 9 Pavel Flaska 2006-09-06 15:05:07 UTC
Fixed in trunk build.

Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java,v
 <--  IndentUtil.java
new revision: 1.15; previous revision: 1.14
done
Checking in test/cfg-unit.xml;
/cvs/java/javacore/test/cfg-unit.xml,v  <--  cfg-unit.xml
new revision: 1.53; previous revision: 1.52
done
RCS file:
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/DefaultTest/AKlas.pass,v
done
Checking in
test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/DefaultTest/AKlas.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/DefaultTest/AKlas.pass,v
 <--  AKlas.pass
initial revision: 1.1
done
RCS file:
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/DefaultTest/BKlas.pass,v
done
Checking in
test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/DefaultTest/BKlas.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/DefaultTest/BKlas.pass,v
 <--  BKlas.pass
initial revision: 1.1
done
RCS file: /cvs/java/javacore/test/unit/data/projects/default/src/AKlas.java,v
done
Checking in test/unit/data/projects/default/src/AKlas.java;
/cvs/java/javacore/test/unit/data/projects/default/src/AKlas.java,v  <--  AKlas.java
initial revision: 1.1
done
RCS file: /cvs/java/javacore/test/unit/data/projects/default/src/BKlas.java,v
done
Checking in test/unit/data/projects/default/src/BKlas.java;
/cvs/java/javacore/test/unit/data/projects/default/src/BKlas.java,v  <--  BKlas.java
initial revision: 1.1
done
RCS file:
/cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/DefaultTest.java,v
done
Checking in test/unit/src/org/netbeans/jmi/javamodel/codegen/DefaultTest.java;
/cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/DefaultTest.java,v
 <--  DefaultTest.java
initial revision: 1.1
done
Comment 10 Pavel Flaska 2006-09-06 15:09:10 UTC
Created attachment 33641 [details]
patch, use when you want to test on different branches
Comment 11 Jan Becicka 2006-09-11 15:44:11 UTC
The fix is safe.
Comment 12 Pavel Flaska 2006-09-11 16:05:55 UTC
Merged from trunk.

Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java,v
 <--  IndentUtil.java
new revision: 1.9.2.2.2.2; previous revision: 1.9.2.2.2.1
done
Comment 13 Quality Engineering 2007-09-20 11:56:03 UTC
Reorganization of java component