It's a trap

It’s a trap
Karol Wrótniak
Ramazan wanted to write "You change
the topic every time you!run out of
arguments" (sounds familiar enough) but
what Emine read was, "You change the
topic every time!they are fucking
you" (sounds familiar too.)
Source: Jesus Diaz, A Cellphone's Missing Dot Kills Two People, Puts Three More in Jail (2008)
Retrieved from: https://gizmodo.com/382026/a-cellphones-missing-dot-kills-two-people-puts-three-more-in-jail
When using!
LOWER_CASE_WITH_DASHES!or!
LOWER_CASE_WITH_UNDERSCORES!
as FieldNamingPolicy it could happen that
certain fields won't get serialized/
deserialized.
I've seen that behavior on devices with a
turkish (tr-TR) locale.!
Source: Sebastian Clan, Fix issues if runing in an environment with a Turkish locale (2015)
Retrieved from: https://github.com/google/gson/pull/652/files
Dotted and dotless I
Lowercase Uppercase
I
!
I
i
i
ı
English
Turkish
Turkish
dotted
dotless
Casing done right
• Default (or specific) locale for UI
• ROOT locale for machine to machine communication like JSON keys or HTTP headers
value.toUpperCase(Locale.ROOT);
Casing depends on context
• Dotted and dotless I in Turkish: !i, Iı
• Final and non-final small Greek sigmas with single capital letter: ", #, "
• Retained dot in a lowercase i and j when followed by accents in Lithuanian: i #$
Unicode casing: https://unicode.org/Public/UNIDATA/
SpecialCasing.txt
It's a trap
It's a trap
Collator
String[] words = {"!ma", "kres", "czas", "chyba"};
Arrays.sort(words);
System.out.println(Arrays.toString(words));
//[chyba, czas, kres, !ma]
Arrays.sort(words, Collator.getInstance());
• Collator PL: [chyba, czas, %ma, kres]
• Collator CS: [%ma, czas, chyba, kres]
• Hungarian SZ+SZ=SSZ
• [kaszinó, kassza]
Source: DailyHaha
Number pitfalls
x == -x && x != 0
int x = Integer.MIN_VALUE;
x != x
float x = Float.NaN;
x = x + y;
x += y;
short x = 1;
int y = 2;
The missing days
Calendar calendar = Calendar.getInstance();
System.out.println(calendar.getTime()); //Sat Oct 06 12:25:24 CEST 2018
calendar.add(YEAR, -436);
System.out.println(calendar.getTime()); //Sat Oct 16 12:25:24 CET 1582
1-1 = ?
Calendar calendar = Calendar.getInstance();
calendar.set(YEAR, 1);
System.out.println(calendar.get(YEAR)); //1
calendar.add(YEAR, -1);
System.out.println(calendar.get(YEAR)); //1
Source: java-gaming.org
java.io.File internals
file.exists() == true;
file.isDirectory() == false;
file.isFile() == false;
File file = new File("/dev/null");
InputStream stream = new FileInputStream(file);
file.delete();
stream.read();
Initialization order
abstract class Parent {
Parent() {
log();
}
abstract void log();
}
class Child extends Parent {
final String foo;
Child() {
foo = "bar";
}
@Override
protected void log() {
System.out.println(foo);
}
}
Abnormal finally block completion
public static void main(String[] args) {
System.out.println(foo());
}
private static boolean foo() {
try {
return false;
} finally {
return true;
}
}
Surprising escapes
/*
String specialChars = "!@#$%*/()";
*/
String x = "au0022;
String x = "a";
//TODO add u000A support
Volatile
private static boolean isReady;
public static void main(String[] args) throws Exception {
new Thread(() -> {
while (!isReady);
System.out.println("Ready!");
}).start();
Thread.sleep(1000);
isReady = true;
}
REFERENCES
• Java Puzzlers
• Edge Cases to Keep in Mind. Part 1 – Text
• Edge Cases to Keep in Mind. Part 2 – Files
• Unicode casing
• Java Magic. Part 4: sun.misc.Unsafe
1 of 20

Recommended

It's a trap - java pitfalls by
It's a trap - java pitfallsIt's a trap - java pitfalls
It's a trap - java pitfallsKarol Wrótniak
88 views21 slides
Linux basic3 by
Linux basic3Linux basic3
Linux basic3Hideo Amezawa
120 views12 slides
Efficient Parallel Set-Similarity Joins Using Hadoop__HadoopSummit2010 by
Efficient Parallel Set-Similarity Joins Using Hadoop__HadoopSummit2010Efficient Parallel Set-Similarity Joins Using Hadoop__HadoopSummit2010
Efficient Parallel Set-Similarity Joins Using Hadoop__HadoopSummit2010Yahoo Developer Network
1.5K views30 slides
JNI - Java & C in the same project by
JNI - Java & C in the same projectJNI - Java & C in the same project
JNI - Java & C in the same projectKarol Wrótniak
89 views46 slides
Bitrise - continuous happiness as a service by
Bitrise - continuous happiness as a serviceBitrise - continuous happiness as a service
Bitrise - continuous happiness as a serviceKarol Wrótniak
142 views24 slides
The forgotten screens - common UI/UX bugs in Android apps by
The forgotten screens - common UI/UX bugs in Android appsThe forgotten screens - common UI/UX bugs in Android apps
The forgotten screens - common UI/UX bugs in Android appsKarol Wrótniak
142 views23 slides

More Related Content

Recently uploaded

A first look at MariaDB 11.x features and ideas on how to use them by
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use themFederico Razzoli
45 views36 slides
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...Deltares
17 views12 slides
Tridens DevOps by
Tridens DevOpsTridens DevOps
Tridens DevOpsTridens
9 views28 slides
Programming Field by
Programming FieldProgramming Field
Programming Fieldthehardtechnology
5 views9 slides
Unleash The Monkeys by
Unleash The MonkeysUnleash The Monkeys
Unleash The MonkeysJacob Duijzer
7 views28 slides
SAP FOR CONTRACT MANUFACTURING.pdf by
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdfVirendra Rai, PMP
11 views2 slides

Recently uploaded(20)

A first look at MariaDB 11.x features and ideas on how to use them by Federico Razzoli
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use them
Federico Razzoli45 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares17 views
Tridens DevOps by Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 views
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j6 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 views
AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8711 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta5 views
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy13 views

Featured

ChatGPT and the Future of Work - Clark Boyd by
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
22.6K views69 slides
Getting into the tech field. what next by
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
5.5K views22 slides
Google's Just Not That Into You: Understanding Core Updates & Search Intent by
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
6.2K views99 slides
How to have difficult conversations by
How to have difficult conversations How to have difficult conversations
How to have difficult conversations Rajiv Jayarajah, MAppComm, ACC
4.7K views19 slides
Introduction to Data Science by
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data ScienceChristy Abraham Joy
82.2K views51 slides
Time Management & Productivity - Best Practices by
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
169.7K views42 slides

Featured(20)

ChatGPT and the Future of Work - Clark Boyd by Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd22.6K views
Getting into the tech field. what next by Tessa Mero
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero5.5K views
Google's Just Not That Into You: Understanding Core Updates & Search Intent by Lily Ray
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray6.2K views
Time Management & Productivity - Best Practices by Vit Horky
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky169.7K views
The six step guide to practical project management by MindGenius
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius36.6K views
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... by RachelPearson36
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson3612.6K views
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by Applitools
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools55.5K views
12 Ways to Increase Your Influence at Work by GetSmarter
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter401.6K views
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G... by DevGAMM Conference
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference3.6K views
Barbie - Brand Strategy Presentation by Erica Santiago
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago25.1K views
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well by Saba Software
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software25.2K views
Introduction to C Programming Language by Simplilearn
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn8.4K views
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr... by Palo Alto Software
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
Palo Alto Software88.4K views
9 Tips for a Work-free Vacation by Weekdone.com
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
Weekdone.com7.2K views
How to Map Your Future by SlideShop.com
How to Map Your FutureHow to Map Your Future
How to Map Your Future
SlideShop.com275.1K views

It's a trap

  • 2. Ramazan wanted to write "You change the topic every time you!run out of arguments" (sounds familiar enough) but what Emine read was, "You change the topic every time!they are fucking you" (sounds familiar too.) Source: Jesus Diaz, A Cellphone's Missing Dot Kills Two People, Puts Three More in Jail (2008) Retrieved from: https://gizmodo.com/382026/a-cellphones-missing-dot-kills-two-people-puts-three-more-in-jail
  • 3. When using! LOWER_CASE_WITH_DASHES!or! LOWER_CASE_WITH_UNDERSCORES! as FieldNamingPolicy it could happen that certain fields won't get serialized/ deserialized. I've seen that behavior on devices with a turkish (tr-TR) locale.! Source: Sebastian Clan, Fix issues if runing in an environment with a Turkish locale (2015) Retrieved from: https://github.com/google/gson/pull/652/files
  • 4. Dotted and dotless I Lowercase Uppercase I ! I i i ı English Turkish Turkish dotted dotless
  • 5. Casing done right • Default (or specific) locale for UI • ROOT locale for machine to machine communication like JSON keys or HTTP headers value.toUpperCase(Locale.ROOT);
  • 6. Casing depends on context • Dotted and dotless I in Turkish: !i, Iı • Final and non-final small Greek sigmas with single capital letter: ", #, " • Retained dot in a lowercase i and j when followed by accents in Lithuanian: i #$ Unicode casing: https://unicode.org/Public/UNIDATA/ SpecialCasing.txt
  • 9. Collator String[] words = {"!ma", "kres", "czas", "chyba"}; Arrays.sort(words); System.out.println(Arrays.toString(words)); //[chyba, czas, kres, !ma] Arrays.sort(words, Collator.getInstance()); • Collator PL: [chyba, czas, %ma, kres] • Collator CS: [%ma, czas, chyba, kres] • Hungarian SZ+SZ=SSZ • [kaszinó, kassza]
  • 11. Number pitfalls x == -x && x != 0 int x = Integer.MIN_VALUE; x != x float x = Float.NaN; x = x + y; x += y; short x = 1; int y = 2;
  • 12. The missing days Calendar calendar = Calendar.getInstance(); System.out.println(calendar.getTime()); //Sat Oct 06 12:25:24 CEST 2018 calendar.add(YEAR, -436); System.out.println(calendar.getTime()); //Sat Oct 16 12:25:24 CET 1582
  • 13. 1-1 = ? Calendar calendar = Calendar.getInstance(); calendar.set(YEAR, 1); System.out.println(calendar.get(YEAR)); //1 calendar.add(YEAR, -1); System.out.println(calendar.get(YEAR)); //1
  • 15. java.io.File internals file.exists() == true; file.isDirectory() == false; file.isFile() == false; File file = new File("/dev/null"); InputStream stream = new FileInputStream(file); file.delete(); stream.read();
  • 16. Initialization order abstract class Parent { Parent() { log(); } abstract void log(); } class Child extends Parent { final String foo; Child() { foo = "bar"; } @Override protected void log() { System.out.println(foo); } }
  • 17. Abnormal finally block completion public static void main(String[] args) { System.out.println(foo()); } private static boolean foo() { try { return false; } finally { return true; } }
  • 18. Surprising escapes /* String specialChars = "!@#$%*/()"; */ String x = "au0022; String x = "a"; //TODO add u000A support
  • 19. Volatile private static boolean isReady; public static void main(String[] args) throws Exception { new Thread(() -> { while (!isReady); System.out.println("Ready!"); }).start(); Thread.sleep(1000); isReady = true; }
  • 20. REFERENCES • Java Puzzlers • Edge Cases to Keep in Mind. Part 1 – Text • Edge Cases to Keep in Mind. Part 2 – Files • Unicode casing • Java Magic. Part 4: sun.misc.Unsafe