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 78613 - resource is not null after being physically deleted
Summary: resource is not null after being physically deleted
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks: 77716
  Show dependency tree
 
Reported: 2006-06-20 17:04 UTC by Jiri Prazak
Modified: 2007-09-26 09:14 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Prazak 2006-06-20 17:04:37 UTC
While using the JMI API for J2MEUnit test generation, when the generated test
class is deleted by the user from the explorer (node action) and then later
there is a request to create the file again MDR still finds the resource even
though the resource is empty and my code therefore tries to update the test
class instead of creating new one.  Naturally the update fails because the
resource it acts on is empty.

I have found a work around for the problem but it should still be looked into as
it might happen again in the future with other components.  The code looks
similar to the following

Resource r=null;
boolean flag=false;
            
JavaModel.getJavaRepository().beginTrans(true);
try {
    JavaClass testedClass=(JavaClass) it.next();
    String pkgName=testedClass.getResource().getPackageName();
    r=testClassExists(testedClass, pkgName);
    //this method returns corresponding resource or null if testClass is not found
    if (r==null) {
         JavaClass testClass=generateTestClass(testedClass);
         //create a file from the JavaClass
         r=testTargetPkg.getResource().createResource(
            TestUtils.getFullTestClassFileName(testedClass),
            System.currentTimeMillis(),
            Collections.singletonList(testClass),
            generateImports(testedClass),
            pkgName,
            null,
            Collections.EMPTY_LIST);
   } else {
         updateTestClass(r, testedClass);
   }
   } catch (Exception e) {
                flag=true;
                System.out.println(e.getMessage());
                e.printStackTrace();
   } finally {
   if (r!=null && !flag) {
      result.add(JavaModel.getFileObject(r));
      JavaModel.getJavaRepository().endTrans();
   } else
      JavaModel.getJavaRepository().endTrans(true);
   }

the resource is variable r.  The workaround was this

if (JavaModel.getFileObject(r)==null && r!=null)
      r.refDelete();
if (JavaModel.getFileObject(r)==null) {
.
.
create new test class
.
.
} else {
.
.
update existing test class
.
.
}
Comment 1 Pavel Flaska 2006-10-26 10:52:07 UTC
APIs changed.
Comment 2 Quality Engineering 2007-09-20 11:54:35 UTC
Reorganization of java component