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 250584 - \u000a character causes NB to ignore following quote
Summary: \u000a character causes NB to ignore following quote
Status: RESOLVED INVALID
Alias: None
Product: editor
Classification: Unclassified
Component: Lexer (show other bugs)
Version: 8.0.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-20 15:45 UTC by EmmaAtkinson
Modified: 2015-02-24 15:33 UTC (History)
1 user (show)

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 EmmaAtkinson 2015-02-20 15:45:23 UTC
Product Version = NetBeans IDE 8.0.2 (Build 201408251540)
Operating System = Linux version 3.16.7-7-desktop running on amd64
Java; VM; Vendor = 1.8.0_20
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.20-b23

    public static void main(String[] args) {

        CharSequence target = "\u000b"; // NB is fine with this
        CharSequence source = "\u000a"; // NB thinks the second quote is missing
        
        ...

    }
Comment 1 EmmaAtkinson 2015-02-20 15:53:21 UTC
I have just discovered the same misbehaviour with 
...
    CharSequence source = "\u0000d"; // NB thinks second quote is missing for Carriage Return too.
Comment 2 Jiri Prox 2015-02-24 13:04:17 UTC
This is as java behaves. The unicode are translated to related character at first,
see http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html
Comment 3 EmmaAtkinson 2015-02-24 13:14:33 UTC
> This is as java behaves. The unicode are translated to related character at first,
> see http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html

I have not described the problem clearly enough.  
I am writing a program that takes a string and swaps control characters for printable characters.
The NB editor will not let me declare a CharSequence that contains a single escaped character equivalent to the unicode representation for \n.  The NB editor misbehaves.  The NB also misbehaves if I try to declare a CharSequence  assigned to a string containing a string with an escaped unicode character for \r, which is \u000d.
Comment 4 Jiri Prox 2015-02-24 13:24:57 UTC
I understand the problem, but the "\u000d" or "\u000a" is not valid code, try to compile the code from command line and you'll see the compilation error as well. 

The reason is described in the java language specification which was provided in comment 2
Comment 5 EmmaAtkinson 2015-02-24 14:14:35 UTC
> I understand the problem, but the "\u000d" or "\u000a" is not valid code, try to compile the code from command line and you'll see the compilation error as well. 
> The reason is described in the java language specification which was provided in comment 2

Thank you for your guidance.  I will reread 3.3 Unicode Escapes to discover whether one can use a unicode escape to insert a newline character into a string.  I'll stop when my head hurts.
Comment 6 Miloslav Metelka 2015-02-24 15:02:08 UTC
The unicode escape sequences are translated to "regular" unicode characters at an early compilation stage (by the java lexer) so simply said the compiler itself only sees physical newline character regardless of whether it was entered as \u000a in the source or whether a regular newline character was present in the source.
Comment 7 EmmaAtkinson 2015-02-24 15:33:27 UTC
Thank you.  I have now discovered some weird code snippets that make my misunderstanding very clear.  The following came from Mark Peters on stackoverflow

public class FalseIsTrue {
    public static void main(String[] args) {
        if ( false == true ) { //these characters are magic: \u000a\u007d\u007b
            System.out.println("false is true!");
        }
    }
}