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 113795 - Code folding (Java) interacts with typing/editing
Summary: Code folding (Java) interacts with typing/editing
Status: RESOLVED WORKSFORME
Alias: None
Product: editor
Classification: Unclassified
Component: Code folding (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-25 17:12 UTC by vinaykagarwal
Modified: 2010-10-21 12:33 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Java file to reproduce the IllegalStateException with NB6.5 dev (19.08 KB, text/plain)
2008-09-09 11:15 UTC, arittner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vinaykagarwal 2007-08-25 17:12:44 UTC
If code folding is enabled (and some parts of code are folded), the code folding is updated on every keystroke. At time
when code blocks are not well formed, it expands previously collapsed folds and expands others. As one can imagine, it
is hard to type when the rest of the file is constantly being moved around.

Correct way to do it would be to NOT expand or collapse code folds unless directed by the user or on file opening.
Comment 1 Vitezslav Stejskal 2007-08-30 11:52:50 UTC
Could you please attach a sample file and describe how this issue can be reproduced? Thank you.
Comment 2 Jiri Prox 2008-04-11 00:43:02 UTC
moving opened issues from TM <= 6.1 to TM=Dev
Comment 3 arittner 2008-07-08 08:23:33 UTC
The "INCOMPLETE"-tag is IMHO not necessary for this issue. The problem is easy to reproduce. On entering closing braces,
inner classes or pasting field declarations into methods, the code folds every time. 

This is very cumbersome and really not necessary.

With enabled code folding for method bodies and inner classes, the block folds immediately on entering a closing brace. 

On autoexpand interfaces with anonymous inner classes (eg. Runnable), the code folds - but the first choice is to
implement the abstract methods. Sample:

new Thread (new Runn|                <- Ctrl-SPACE, choose java.lang.Runnable, ENTER

new Thread (new Runnable() [...]|);

Now I need to open the inner class with Ctrl-PLUS. But the implemented method run() is closed... ok, moving the caret to
the method signature, enter Ctrl+PLUS again and now I can move to the "new UnsupportedOperationException". 

This is a far too cumbersome approach.

Please, disable the code folding on editing. I'm of the opinion that nobody really need this feature. I hope it is no
exaggeration that I increased the priority to P3.

Best regards,
  Josh.


Comment 4 Jiri Prox 2008-07-08 09:09:33 UTC
reproducible - no INCOMPLETE is really needed


Product Version: NetBeans IDE Dev (Build 20080707055228)
Java: 1.6.0_10-beta; Java HotSpot(TM) Client VM 11.0-b12
System: Linux version 2.6.22-15-generic running on i386; UTF-8; en_US (nb)
Userdir: /home/jp159440/.netbeans/dev
Comment 5 arittner 2008-09-09 11:13:26 UTC
IMHO the issue should be a P2 bug for target 6.5

In NetBeans 6.5 dev:

Copy this string:

protected static boolean breakSplash = false;

into the clipboard.

Create an class with an empty constructor:

Paste the clipboard string into the contructor body. The c'tor folds and I get an IllegalStateException.

Stacktrace for my real application (not an empty class):
WARNUNG [org.netbeans.api.java.source.JavaSource]: JavaSource.runUserActionTask called in AWT event thread by:
org.netbeans.modules.editor.java.JavaCodeTemplateFilter.<init>(JavaCodeTemplateFilter.java:78)
SEVERE [global]
java.lang.IllegalStateException: Please attach the stack trace and if possible also the edited source file
'C:\Entw\Work\svn\S3\src\AdmSoftware\App\mainLoader.java' to issue http://www.netbeans.org/issues/show_bug.cgi?id=134663
kind: CLASS
tree: '
public static class SplashWindow extends Frame {
    private Image imageLogo;
    private Image image;
    private String updateVersion = Pool.getProperty("Update.Version", "0");
    
    public SplashWindow(String specialImageName, String defaultImageName, String logoName) {
        super();
        setUndecorated(true);
        setSize(400, 261);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension dialogSize = getSize();
        setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
        setBackground(Color.black);
        try {
            ImageResource ir = new ImageResource(specialImageName);
            image = ir.getImage();
        } catch (java.io.IOException ioe) {
            try {
                ImageResource ir = new ImageResource(defaultImageName);
                image = ir.getImage();
                ImageResource irLogo = new ImageResource(logoName);
                imageLogo = irLogo.getImage();
            } catch (java.io.IOException ioe2) {
                System.out.println("Kann Splash-Grafiken nicht laden... " + ioe2);
            }
        }
        if (image != null) {
            MediaTracker md = new MediaTracker(SplashWindow.this);
            try {
                md.addImage(image, 0);
                if (imageLogo != null) md.addImage(imageLogo, 1);
                md.waitForID(0);
                if (imageLogo != null) md.waitForID(1);
            } catch (InterruptedException ie) {
                ;
            }
            BufferedImage buf = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
            Graphics gImage = buf.getGraphics();
            gImage.drawImage(image, 0, 0, null);
            if (gImage != null) {
                if (imageLogo != null) {
                    gImage.drawImage(imageLogo, 255, 200, null);
                }
                String javaVersion = System.getProperty("java.runtime.version");
                gImage.setColor(Color.darkGray);
                if (!updateVersion.equals("0")) {
                    gImage.drawString("u-" + updateVersion + "      JRE: " + javaVersion, 50, 163);
                } else {
                    gImage.drawString("JRE: " + javaVersion, 50, 163);
                }
            }
            image = buf;
        }
        this.repaint();
    }
    
    public void update(Graphics g) {
        paint(g);
    }
    
    public void paint(Graphics g) {
        if (image != null) {
            g.drawImage(image, 0, 0, null);
        } else {
            g.setColor(Color.white);
            g.drawString("Sepix Sales System wird geladen...", 20, 100);
        }
    }
}'
	at org.netbeans.modules.javadoc.hints.Analyzer$1.run(Analyzer.java:664)
	at org.netbeans.editor.BaseDocument.render(BaseDocument.java:1366)
	at org.netbeans.modules.javadoc.hints.Analyzer.createSignaturePositions(Analyzer.java:651)
	at org.netbeans.modules.javadoc.hints.Analyzer.analyze(Analyzer.java:197)
	at org.netbeans.modules.javadoc.hints.JavadocHintProvider.run(JavadocHintProvider.java:121)
	at org.netbeans.modules.java.hints.infrastructure.SuggestionsTask.run(SuggestionsTask.java:122)
	at org.netbeans.modules.java.hints.infrastructure.SuggestionsTask.run(SuggestionsTask.java:65)
[catch] at org.netbeans.api.java.source.JavaSource$CompilationJob.run(JavaSource.java:1683)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
	at java.lang.Thread.run(Thread.java:619)

Please note, the SplashWindow is an embedded static class in the MainLoader class. I've copied the string "protected
static boolean breakSplash = false;" into the empty private c'tor from the MainLoader class.

>System Info: 
  Product Version         = NetBeans IDE Dev (Build 200809081401)
  Operating System        = Windows XP version 5.1 running on x86
  Java; VM; Vendor        = 1.6.0_03; Java HotSpot(TM) Client VM 1.6.0_03-b05; Sun Microsystems Inc.
  Runtime                 = Java(TM) SE Runtime Environment 1.6.0_03-b05
  Java Home               = C:\Entw\jdk\1.6.0\jre


best regards,
  josh.
Comment 6 arittner 2008-09-09 11:16:15 UTC
Created attachment 69390 [details]
Java file to reproduce the IllegalStateException with NB6.5 dev
Comment 7 Vitezslav Stejskal 2008-09-09 12:39:28 UTC
Ehm, I'm sorry, this is probably obvious, but what are your code folding settings? I mean what checkboxes in
Tools-Options -> Editor -> General -> Code Folding have you got ticked? I assume at least 'Use Code Folding', 'Methods'
and 'Inner classes'; maybe even the other. I understand that typing code with these options on is painfully hard.
Perhaps as you mentioned here we could only apply these options when a file is opened or/and when the options change.

The ISE is unrelated to code folding and it's coming from Javadoc hints. Please see the message, it refers to issue
#134663, which was fixed on Sep 5th, 2008. If you got the exception from an older build please download a newer one and
try it again. If you are positive that the exception came from a build that already contains the fix of #134663 please
attach the stacktrace to issue #134663 as the exception message says. Thanks
Comment 8 arittner 2008-09-09 13:15:58 UTC
My options are:

Use code folding [X]
[X] Methods
[X] Inner Classes
[X] Imports
[ ] Javadoc Comments
[X] Initial comment

> Perhaps as you mentioned here we could only apply these options when a file is opened or/and when the options change.

Yes, this was the old behavior (IMHO) before NB 6.0

> If you are positive that the exception came from a build that already contains the fix of #134663

The exception is from build NetBeans IDE Dev (Build 200809081401) and is a IllegalStateExc, not a NPE. But I'll post the
stacktrace to the other issue.

best regards,
  josh.
Comment 9 David Strupl 2009-06-08 14:00:24 UTC
Marek, these are yours now ...
Comment 10 mdm42 2010-01-31 06:38:35 UTC
Still present in 6.8. I strongly suggest that this be bumped to P2! Note that the situation is even worse editing JSPs, where folds frequently and randomly get collapsed at all sort of inconvenient times. VERY annoying!
Comment 11 Miloslav Metelka 2010-10-21 12:33:45 UTC
The related issue seems to be fixed so I suppose that this issue does not happen anymore as well in recent builds.
If a similar problem happens in jsp please file a separate issue on "web" component.