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.
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 . . }
APIs changed.
Reorganization of java component