Skip to main content

Posts

Showing posts with the label Java Interview Prep

πŸ’₯ "Wait... Why Is It NULL?!?" — When @Value("${...}") Ignores Your Static Field 😡‍πŸ’«

πŸ”  A surprising Spring Boot moment I didn't expect — and the rabbit hole it took me down... 🎬 It All Started With a Simple Idea... You know how it goes… You define a config value like this in application.properties : payment.currency=INR And then you boldly write this innocent-looking code: @Component public class PaymentUtil { @Value("${payment.currency}") private static String currency; // ✅ Logical! Right? public static void printCurrency() { System.out.println("Currency: " + currency); } } You run the app. And BAM πŸ’₯ Currency: null 😡 "Eh? I clearly defined the property. Is it not reading the file? Do I need a restart? Do I need to yell at my laptop?" 🀯 The Shocking Discovery Spring doesn’t inject values into static fields. Yes, my friend. Even if you beg it with @Value . And trust me — it’s not a bug. It’s a feature. πŸ™ƒ 🧠 What Is This Dependency Injection (DI) Sorcery ...

🧠 Java Production Trap I’ll Never Forget – Let’s Talk About ConcurrentModificationException

  πŸ’¬ “When I was a fresher, I used to wonder: what things should I never do in Java?” That curiosity led me to explore tons of weird bugs and war stories people had faced in production. Some were scary, some silly — but all of them were super valuable to understand deeply. Today, I’m sharing one such issue I came across. ⚠️ P.S. I didn’t write this code — but I sure learned a lot digging into what went wrong and how it was fixed. πŸ˜… This post is for the curious devs out there — especially freshers who want to learn the "why" behind Java's behaviors, not just memorize "what to do". πŸ’₯ The Problem: ConcurrentModificationException in a Simple Loop πŸ“Environment: This happened in a Spring Boot microservice deployed on OpenShift (Linux-based). Interestingly, it didn’t throw any error in the developer's local Windows machine during testing. But in prod? BOOM. πŸ’£ Here’s the actual buggy code snippet: List<String> users = getActiveUsers(); // ...