SlideShare a Scribd company logo
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
Where is my uppercase?
•No uppercase for some ligatures: ß SS, ffl FFL
•No uppercase for some precomposed characters: ΐ (1 character) Ϊ́ (3 characters)
"ß".toUpperCase() == "SS";
"dzwon".length() == 4;
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;
}
}
Exceptional exceptions
public static <T extends Throwable> void sneakyThrow(Throwable t) throws T {
throw (T) t;
}
public static void main(String[] args) {
sneakyThrow(new IOException());
}
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
THANKS!
ANY QUESTIONS?
karol.wrotniak@droidsonroids.pl
koral--
karol-wrotniak
@karol.wrotniak
Karol Wrótniak
Android Dev @Droids On Roids
Co-organizer @GDG Wrocław

More Related Content

PDF
It's a trap
PPT
Efficient Parallel Set-Similarity Joins Using Hadoop__HadoopSummit2010
PDF
Velocity 2015-final
PDF
JNI - Java & C in the same project
PDF
Bitrise - continuous happiness as a service
PDF
The forgotten screens - common UI/UX bugs in Android apps
PDF
JNI - Java & C in the same project
PDF
Bitrise & OpenSTF
It's a trap
Efficient Parallel Set-Similarity Joins Using Hadoop__HadoopSummit2010
Velocity 2015-final
JNI - Java & C in the same project
Bitrise - continuous happiness as a service
The forgotten screens - common UI/UX bugs in Android apps
JNI - Java & C in the same project
Bitrise & OpenSTF

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
A Presentation on Artificial Intelligence
PDF
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MYSQL Presentation for SQL database connectivity
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Monthly Chronicles - July 2025
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
A Presentation on Artificial Intelligence
KodekX | Application Modernization Development
Ad
Ad

It's a trap - java pitfalls

  • 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
  • 7. Where is my uppercase? •No uppercase for some ligatures: ß SS, ffl FFL •No uppercase for some precomposed characters: ΐ (1 character) Ϊ́ (3 characters) "ß".toUpperCase() == "SS"; "dzwon".length() == 4;
  • 8. 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]
  • 10. 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;
  • 11. 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
  • 12. 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
  • 14. 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();
  • 15. 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); } }
  • 16. Abnormal finally block completion public static void main(String[] args) { System.out.println(foo()); } private static boolean foo() { try { return false; } finally { return true; } }
  • 17. Exceptional exceptions public static <T extends Throwable> void sneakyThrow(Throwable t) throws T { throw (T) t; } public static void main(String[] args) { sneakyThrow(new IOException()); }
  • 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