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 257366 - NetBeans creates unuseable .form file
Summary: NetBeans creates unuseable .form file
Status: RESOLVED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.1
Hardware: PC Windows 10 x64
: P3 normal (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-02 20:19 UTC by Jelec
Modified: 2016-01-06 02:17 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 Jelec 2016-01-02 20:19:02 UTC
Hi
When switching to GUI designer of JForm, JPanel and other presets for .java files which allow useage of GUI designer, following error appears:

    The form file does not contain valid XML. The form cannot be opened.

    Content is not allowed in prolog.

The JFrame.form file contains something like this:

   <   ?   x   m   l       v   e   r   s   i   o   n   =   "   1   .   0   "       e   n   c   o   d   i   n   g   =   "   U   T   F   -   8   "       ?   >   
   
   <   F   o   r   m       v   e   r   s   i   o   n   =   "   1   .   3   "       t   y   p   e   =   "   o   r   g   .   n   e   t   b   e   a   n   s   .   m   o   d   u   l   e   s   .   f   o   r   m   .   f   o   r   m   i   n   f   o   .   J   F   r   a   m   e   F   o   r   m   I   n   f   o   "   >   
           <   P   r   o   p   e   r   t   i   e   s   >   
                   <   P   r   o   p   e   r   t   y       n   a   m   e   =   "   d   e   f   a   u   l   t   C   l   o   s   e   O   p   e   r   a   t   i   o   n   "       t   y   p   e   =   "   i   n   t   "       v   a   l   u   e   =   "   3   "   /   >   
           <   /   P   r   o   p   e   r   t   i   e   s   >   
           <   S   y   n   t   h   e   t   i   c   P   r   o   p   e   r   t   i   e   s   >   
                   <   S   y   n   t   h   e   t   i   c   P   r   o   p   e   r   t   y       n   a   m   e   =   "   f   o   r   m   S   i   z   e   P   o   l   i   c   y   "       t   y   p   e   =   "   i   n   t   "       v   a   l   u   e   =   "   1   "   /   >   
           <   /   S   y   n   t   h   e   t   i   c   P   r   o   p   e   r   t   i   e   s   >   
   
           <   L   a   y   o   u   t   >   
                   <   D   i   m   e   n   s   i   o   n   L   a   y   o   u   t       d   i   m   =   "   0   "   >   
                           <   G   r   o   u   p       t   y   p   e   =   "   1   0   3   "       g   r   o   u   p   A   l   i   g   n   m   e   n   t   =   "   0   "       a   t   t   r   i   b   u   t   e   s   =   "   0   "   >   
                                           <   E   m   p   t   y   S   p   a   c   e       m   i   n   =   "   0   "       p   r   e   f   =   "   4   0   0   "       m   a   x   =   "   3   2   7   6   7   "       a   t   t   r   i   b   u   t   e   s   =   "   0   "   /   >   
                           <   /   G   r   o   u   p   >   
                   <   /   D   i   m   e   n   s   i   o   n   L   a   y   o   u   t   >   
                   <   D   i   m   e   n   s   i   o   n   L   a   y   o   u   t       d   i   m   =   "   1   "   >   
                           <   G   r   o   u   p       t   y   p   e   =   "   1   0   3   "       g   r   o   u   p   A   l   i   g   n   m   e   n   t   =   "   0   "       a   t   t   r   i   b   u   t   e   s   =   "   0   "   >   
                                           <   E   m   p   t   y   S   p   a   c   e       m   i   n   =   "   0   "       p   r   e   f   =   "   3   0   0   "       m   a   x   =   "   3   2   7   6   7   "       a   t   t   r   i   b   u   t   e   s   =   "   0   "   /   >   
                           <   /   G   r   o   u   p   >   
                   <   /   D   i   m   e   n   s   i   o   n   L   a   y   o   u   t   >   
           <   /   L   a   y   o   u   t   >   
   <   /   F   o   r   m   >   

This does happen only in case of newly created projects. Creating a JForm file in the old ones works fine and the .form file is not corrupted.
This happens in case of every newly created project. I tried to reinstall NetBeans but it didn't help.
Comment 1 Tomas Pavek 2016-01-04 10:18:54 UTC
Looks like the form file was saved in unicode (utf-16) but not read as such. I can reproduce it by setting project encoding to utf-16. As a workaround, setting the project encoding to utf-8 could help.

Are your new projects created with utf-16 by default? Might be a JDK issue if it claims it is the default platform encoding. You can try to add -J-Dfile.encoding=UTF-8 to netbeans_default_options parameter in the netbeans.conf file, then new projects should hopefully be created with utf-8 as well.

Anyway, GUI forms xml should always be saved in utf-8, that is a bug.
Comment 2 Jelec 2016-01-04 17:48:47 UTC
Switching the project encoding to UTF-8 helps.
Default encoding for a new project is UTF-32.

Using GUI designer with windows-1250 encoding works fine.
Comment 3 Tomas Pavek 2016-01-05 12:51:33 UTC
During form creation all template files go through a scripting engine and are written down in the actual project encoding.

For the form file there is no need for any template processing (unlike with java file). I've made a fix that does just a plain file copy that preserves the utf-8 encoding.
http://hg.netbeans.org/jet-main/rev/96d37de8a7a7
Comment 4 Quality Engineering 2016-01-06 02:17:17 UTC
Integrated into 'main-silver', will be available in build *201601060002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/96d37de8a7a7
User: Tomas Pavek <tpavek@netbeans.org>
Log: #257366: handle form file creation from template as plain file copy, avoiding writing in other than utf-8 encoding