Buggy code:
public class TestFetchPlan extends BaseKernelTest { static Object _rootDirId ; static Object _rootCompanyId ; static final int MAX_DEPTH = 5 ; static final int MAX_CHILD = 3 ; static final String quote = "\"" ; private static boolean firstTime = true ; public TestFetchPlan ( ) { } public TestFetchPlan ( String name ) { } public void setUp ( ) throws Exception { } void createTestData ( ) { } public void testZeroRecursionDepthSingleValuedField ( ) { } public void testOneRecursionDepthSingleValuedField ( ) { } public void testTwoRecursionDepthSingleValuedField ( ) { } public void testThreeRecursionDepthSingleValuedField ( ) { } public void testInfiniteRecursionDepthSingleValuedField ( ) { } public void genericTestForSingleValuedRecursiveField ( String plan , int rd , int fd ) { } PCDirectory queryDirectoryWithPlan ( String plan , int rd , int fd ) { } void checkParents ( PCDirectory result , int D , int L ) { } PCDirectory [ ] getParents ( PCDirectory dir , int depth ) { } void assertNullParent ( PCDirectory [ ] parents , int L ) { } String getDirectoryName ( int depth ) { } String getFileName ( int depth ) { } String quoted ( String s ) { } public void testRelationTraversal ( ) { } public void testRelationTraversalTruncated ( ) { } public void testRelationTraversalWithCompanyAsRoot ( ) { } public void testDetachedRelationTraversalWithCompanyAsRoot ( ) { OpenJPAEntityManager pm = getPM ( ) ; FetchPlan plan = pm . getFetchPlan ( ) ; pm . getFetchPlan ( ) . setMaxFetchDepth ( 2 ) ; plan . addFetchGroup ( "company.departments" ) ; plan . addFetchGroup ( "company.address" ) ; plan . addFetchGroup ( "department.employees" ) ; plan . addFetchGroup ( "person.address" ) ; plan . addFetchGroup ( "address.country" ) ; PCCompany company1 = ( ( PCCompany ) ( pm . find ( PCCompany . class , TestFetchPlan . _rootCompanyId ) ) ) ; <START_BUG> PCCompany company = ( ( PCCompany ) ( pm . detach ( company1 ) ) ) ; <END_BUG> assertTrue ( "company<seq2seq4repair_space>is<seq2seq4repair_space>equal<seq2seq4repair_space>company1" , ( company != company1 ) ) ; Set departments = ( ( Set ) ( PCCompany . reflect ( company , "departments" ) ) ) ; assertNotNull ( "department<seq2seq4repair_space>is<seq2seq4repair_space>null" , departments ) ; assertEquals ( "department<seq2seq4repair_space>size<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>2" , 2 , departments . size ( ) ) ; PCDepartment dept = ( ( PCDepartment ) ( departments . iterator ( ) . next ( ) ) ) ; assertNotNull ( "dept<seq2seq4repair_space>is<seq2seq4repair_space>null" , dept ) ; Set employees = ( ( Set ) ( PCDepartment . reflect ( dept , "employees" ) ) ) ; assertNotNull ( "employee<seq2seq4repair_space>is<seq2seq4repair_space>null" , employees ) ; assertEquals ( "employees<seq2seq4repair_space>size<seq2seq4repair_space>not<seq2seq4repair_space>1" , 1 , employees . size ( ) ) ; PCEmployee emp = ( ( PCEmployee ) ( employees . iterator ( ) . next ( ) ) ) ; assertNotNull ( "emp<seq2seq4repair_space>is<seq2seq4repair_space>null" , emp ) ; PCAddress eaddr = ( ( PCAddress ) ( PCPerson . reflect ( emp , "address" ) ) ) ; PCAddress caddr = ( ( PCAddress ) ( PCCompany . reflect ( company , "address" ) ) ) ; assertNull ( "eaddr<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>null" , eaddr ) ; assertNotNull ( "caddr<seq2seq4repair_space>is<seq2seq4repair_space>null" , caddr ) ; PCCountry country = ( ( PCCountry ) ( PCAddress . reflect ( caddr , "country" ) ) ) ; assertNotNull ( "country<seq2seq4repair_space>is<seq2seq4repair_space>null" , country ) ; } public void testDefaultFetchGroup ( ) { } public void testDefaultFetchGroupExistsByDefault ( ) { } public void testDefaultFetchGroupCanBeRemoved ( ) { } public void tearDown ( ) throws Exception { } private void clearTestData ( ) throws Exception { } }

Fix:
PCCompany company = ( ( PCCompany ) ( pm . detachCopy ( company1 ) ) ) ;