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 108762 - ACTIONS: Action editor allows to set special characters in action's name
Summary: ACTIONS: Action editor allows to set special characters in action's name
Status: VERIFIED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: App Framework (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Joshua Marinacci
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-03 15:31 UTC by Jana Maleckova
Modified: 2007-07-23 16:16 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jana Maleckova 2007-07-03 15:31:36 UTC
Product Version: NetBeans IDE Dev (Build 200707030324) Java: 1.6.0_02-ea; Java HotSpot(TM) Client VM 1.6.0_02-ea-b02
System: Windows XP version 5.1 running on x86; Cp1252; en_GB (nb)

Description:
============
Action editor now allow to create action which name begins with special character ... like \, ^, % and so on ...
Editor warms user, this name is not valid, but method with this syntax is created and then it causes errors during
project compiling. This action is not possible to delete in correct way, using Application Action Editor...
Comment 1 Joshua Marinacci 2007-07-12 20:55:41 UTC
-----
/*
 * DesktopApplication1View.java
 */

package desktopapplication1;

import application.Action;
import application.ResourceMap;
import application.SingleFrameApplication;
import application.FrameView;
import application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class DesktopApplication1View extends FrameView {

    public DesktopApplication1View(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @application.Action
    public void showAboutBox(ActionEvent e) {
        if (aboutBox == null) {
            JFrame mainFrame = DesktopApplication1.getApplication().getMainFrame();
            aboutBox = new DesktopApplication1AboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        DesktopApplication1.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        jButton1.setText("jButton1");

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap(183, Short.MAX_VALUE)
                .add(jButton1)
                .add(136, 136, 136))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .add(45, 45, 45)
                .add(jButton1)
                .addContainerGap(166, Short.MAX_VALUE))
        );

        application.ResourceMap resourceMap = application.Application.getInstance(desktopapplication1.DesktopApplication1.class).getContext
().getResourceMap(DesktopApplication1View.class);
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N

        javax.swing.ActionMap actionMap = application.Application.getInstance(desktopapplication1.DesktopApplication1.class).getContext().getActionMap
(DesktopApplication1View.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

        org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .add(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(statusMessageLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 204, Short.MAX_VALUE)
                .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelLayout.createSequentialGroup()
                .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(statusMessageLabel)
                    .add(statusAnimationLabel)
                    .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
-----
WARNING [global]: java.lang.IllegalArgumentException: Illegal values: from = 3398; to = 3397.Please, attach your messages.log to new issue!
java.lang.IllegalArgumentException: Illegal values: from = 3398; to = 3397.Please, attach your messages.log to new issue!
        at org.netbeans.modules.java.source.save.CasualDiff.copyTo(CasualDiff.java:2585)
        at org.netbeans.modules.java.source.save.CasualDiff.copyTo(CasualDiff.java:2576)
        at org.netbeans.modules.java.source.save.CasualDiff.diffAnnotation(CasualDiff.java:1178)
        at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:2255)
        at org.netbeans.modules.java.source.save.CasualDiff.diffList(CasualDiff.java:1737)
        at org.netbeans.modules.java.source.save.CasualDiff.diffModifiers(CasualDiff.java:1198)
        at org.netbeans.modules.java.source.save.CasualDiff.diffMethodDef(CasualDiff.java:338)
        at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:2140)
        at org.netbeans.modules.java.source.save.CasualDiff.diffListImports(CasualDiff.java:1916)
        at org.netbeans.modules.java.source.save.CasualDiff.diffClassDef(CasualDiff.java:313)
        at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:2137)
        at org.netbeans.modules.java.source.save.CasualDiff.diffListImports(CasualDiff.java:1880)
        at org.netbeans.modules.java.source.save.CasualDiff.diffTopLevel(CasualDiff.java:135)
        at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:2131)
        at org.netbeans.modules.java.source.save.CasualDiff.diff(CasualDiff.java:88)
        at org.netbeans.modules.java.source.save.Commit.commit(Commit.java:177)
        at org.netbeans.modules.java.source.save.Commit.visitCompilationUnit(Commit.java:129)
Caused: QueryException
        at org.netbeans.modules.java.source.query.Query.error(Query.java:117)
        at org.netbeans.modules.java.source.save.Commit.visitCompilationUnit(Commit.java:137)
        at org.netbeans.modules.java.source.save.Commit.visitCompilationUnit(Commit.java:52)
        at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:476)
        at org.netbeans.modules.java.source.engine.RootTree.accept(RootTree.java:60)
        at org.netbeans.modules.java.source.query.Query.apply(Query.java:95)
        at org.netbeans.modules.java.source.save.Commit.commit(Commit.java:85)
[catch] at org.netbeans.api.java.source.WorkingCopy.getChanges(WorkingCopy.java:207)
        at org.netbeans.api.java.source.JavaSource.runModificationTask(JavaSource.java:785)
        at org.netbeans.modules.swingapp.ActionManager.updateActionMethod(ActionManager.java:713)
        at org.netbeans.modules.swingapp.ActionManager.access$000(ActionManager.java:97)
        at org.netbeans.modules.swingapp.ActionManager$5.run(ActionManager.java:663)
        at java.lang.Thread.run(Thread.java:613)
Comment 2 Joshua Marinacci 2007-07-12 20:56:44 UTC
Ignore the previous comment. that was meant for a different bug.
Comment 3 Joshua Marinacci 2007-07-12 21:01:54 UTC
The editor will properly prevent the user from using the invalid method name if the editor is invoked from the property sheet. However, if the user uses the 
'set action' context menu item then the user will get a 'no valid value' dialog, and then the method will be created. It should behave the same as the property 
sheet version.
Comment 4 Joshua Marinacci 2007-07-12 21:16:40 UTC
This is fixed. The ActionEditor will now properly throw a PropertyVetoException if the method name starts with anything other than a letter or if the name 
contains a non-word character.
Comment 5 Tomas Pavek 2007-07-13 10:25:29 UTC
The name is not checked properly - now it does not allow to enter multibyte characters (e.g. Czech letters) which should
be possible.

Note you should use org.openide.util.Utilities.isJavaIdentifier for checking the name.
Comment 6 Joshua Marinacci 2007-07-13 19:54:29 UTC
The code now uses the org.openide.util.Utilities.isJavaIdentifier() method to check the method name.  This bug is fixed now.
Comment 7 Jana Maleckova 2007-07-23 16:16:13 UTC
verified on

Product Version: NetBeans IDE Dev (Build 070723) Java: 1.6.0_02; Java HotSpot(TM) Client VM 1.6.0_02-b05 System: Windows
XP version 5.1 running on x86; Cp1252; en_GB (nb)