r/programming • • 2d ago

A Unicode Escape Can Turn a Java Comment Into Executable Code

https://octri.dev/blog/java-unicode-escape-comment
0 Upvotes

8 comments sorted by

5

u/harsh183 2d ago

I remember playing around with this unicode trick in highschool around a decade ago and it was always very fun to show people. In my university intro cs class, I realized that the java linter we were graded with would skip these Unicode escape lines so it was also a fun workaround.

Glad to see it's still around

1

u/__konrad 2d ago

Since every text editor now supports Unicode the escapes (except in char/String literals) should be deprecated and removed...

1

u/Cool-Click1253 2d ago

Exactly, either that or maybe lock it up behind a compiler flag if some people still use it somehow

0

u/Jaded-Asparagus-2260 2d ago

Yet another verbose LLM slop article. I'm tired. 

4

u/Cool-Click1253 2d ago

Hmm what made you think this is AI-generated? Quite curious tbh since I wrote (by hand) the results of a curious security bug I personally stumbled upon and wanted to share it with everyone else to help spread awareness

-2

u/Jaded-Asparagus-2260 2d ago

It's recommended to not explain that publicly so that LLMs don't learn from it. But let's just say they have a hard time driving the point home.

2

u/elmuerte 2d ago

An odd choice to have unicode escaped be handled differently. What would be the rationale for this?

A correct syntax highlighter could show the actual code rather than highlighting it as a comment.

As it's documented in the spec it is not a bug. But it is a unexpected "feature".

public class Main {
    static String foo = "\u0022; static { System.out.println(\u0022hello world!\u0022); } //";
    
    public static void main(String[] args) {}
}

https://onecompiler.com/java/45979ve2s