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

Summary: resource is not null after being physically deleted
Product: java Reporter: Jiri Prazak <bohemius>
Component: UnsupportedAssignee: Pavel Flaska <pflaska>
Status: RESOLVED WONTFIX    
Severity: blocker    
Priority: P3    
Version: 5.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on:    
Bug Blocks: 77716    

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