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.

View | Details | Raw Unified | Return to bug 41382
Collapse All | Expand All

(-)src/org/openide/loaders/DataFolder.java (-10 / +15 lines)
Lines 524-530 Link Here
524
    * @return the new object
524
    * @return the new object
525
    */
525
    */
526
    protected DataObject handleCopy (DataFolder f) throws IOException {
526
    protected DataObject handleCopy (DataFolder f) throws IOException {
527
        testNesting(f);
527
        testNesting(this, f);
528
        
528
        
529
        Enumeration en = children ();
529
        Enumeration en = children ();
530
530
Lines 550-569 Link Here
550
        return newFolder;
550
        return newFolder;
551
    }
551
    }
552
552
553
    // test whether the "f" is not parent of "this" -> not allowed
553
    /**
554
    private void testNesting(DataFolder f) throws IOException {
554
     * Ensure that given folder is not parent of targetFolder. Also
555
        if (f.equals(this)) {
555
     * ensure that they are not equal.
556
     */
557
    static void testNesting(DataFolder folder, DataFolder targetFolder) throws IOException {
558
        if (targetFolder.equals(folder)) {
556
            throw (IOException) ErrorManager.getDefault().annotate(
559
            throw (IOException) ErrorManager.getDefault().annotate(
557
                new IOException("Error Copying File or Folder"), //NOI18N
560
                new IOException("Error Copying File or Folder"), //NOI18N
558
                ErrorManager.WARNING, null, NbBundle.getMessage(DataFolder.class, "EXC_CannotCopyTheSame", getName()) //NOI18N
561
                ErrorManager.WARNING, null, NbBundle.getMessage(DataFolder.class, "EXC_CannotCopyTheSame", folder.getName()) //NOI18N
559
                , null, null);
562
                , null, null);
560
        } else {
563
        } else {
561
            DataFolder testFolder = f.getFolder();
564
            DataFolder testFolder = targetFolder.getFolder();
562
            while (testFolder != null) {
565
            while (testFolder != null) {
563
                if (testFolder.equals(this)) {
566
                if (testFolder.equals(folder)) {
564
                    throw (IOException) ErrorManager.getDefault().annotate(
567
                    throw (IOException) ErrorManager.getDefault().annotate(
565
                        new IOException("Error copying file or folder: " + testFolder.getPrimaryFile() + " in " + getPrimaryFile()), //NOI18N
568
                        new IOException("Error copying file or folder: " + 
566
                        ErrorManager.WARNING, null, NbBundle.getMessage(DataFolder.class, "EXC_CannotCopySubfolder", getName()) //NOI18N
569
                        folder.getPrimaryFile() + " cannot be copied to its subfolder " +
570
                        targetFolder.getPrimaryFile()), //NOI18N
571
                        ErrorManager.WARNING, null, NbBundle.getMessage(DataFolder.class, "EXC_CannotCopySubfolder", folder.getName()) //NOI18N
567
                        , null, null);
572
                        , null, null);
568
                }
573
                }
569
                testFolder = testFolder.getFolder();
574
                testFolder = testFolder.getFolder();
Lines 791-797 Link Here
791
    */
796
    */
792
    protected DataShadow handleCreateShadow (DataFolder f) throws IOException {
797
    protected DataShadow handleCreateShadow (DataFolder f) throws IOException {
793
        // #33871 - prevent creation of recursive folder structure
798
        // #33871 - prevent creation of recursive folder structure
794
        testNesting(f);
799
        testNesting(this, f);
795
        
800
        
796
        String name;
801
        String name;
797
        if (getPrimaryFile ().isRoot ()) {
802
        if (getPrimaryFile ().isRoot ()) {
(-)src/org/openide/loaders/DataShadow.java (+17 lines)
Lines 552-557 Link Here
552
    * @return the shadow
552
    * @return the shadow
553
    */
553
    */
554
    protected DataShadow handleCreateShadow (DataFolder f) throws IOException {
554
    protected DataShadow handleCreateShadow (DataFolder f) throws IOException {
555
        if (getOriginal() instanceof DataFolder) {
556
            DataFolder.testNesting(((DataFolder)getOriginal()), f);
557
        }
555
        return original.handleCreateShadow (f);
558
        return original.handleCreateShadow (f);
556
    }
559
    }
557
560
Lines 655-660 Link Here
655
        }, 100);
658
        }, 100);
656
    }
659
    }
657
    
660
    
661
    protected DataObject handleCopy (DataFolder f) throws IOException {
662
        if (getOriginal() instanceof DataFolder) {
663
            DataFolder.testNesting(((DataFolder)getOriginal()), f);
664
        }
665
        return super.handleCopy(f);
666
    }
667
    
668
    protected FileObject handleMove (DataFolder f) throws IOException {
669
        if (getOriginal() instanceof DataFolder) {
670
            DataFolder.testNesting(((DataFolder)getOriginal()), f);
671
        }
672
        return super.handleMove(f);
673
    }
674
658
    private static class OrigL implements PropertyChangeListener {
675
    private static class OrigL implements PropertyChangeListener {
659
        WeakReference shadow = null;
676
        WeakReference shadow = null;
660
        public OrigL (DataShadow shadow) {
677
        public OrigL (DataShadow shadow) {

Return to bug 41382