Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Reflections on Privacy

    CodeSOD: Reflections on Privacy

    July 25, 2024

    Jaco‘s team had a problems with making an embedded web server shut down properly. Something about the shutdown process was deadlocking, so one of their “ninja Yoda coders” rockstarred their way to a solution.

    private void stopServer() {
    try {
    if (webServer != null) {
    logger.debug(“Shutdown webserver”);
    // This goes into a dead lock, therefore I’ve replaced it with
    // some voodoo stuff.
    logger.debug(“Get listener field from web server.”);
    Field listenerField = WebServer.class.getDeclaredField(“listener”);
    listenerField.setAccessible(true);
    Thread listener = (Thread) listenerField.get(webServer);
    listenerField.set(webServer, null);
    logger.debug(“Interrupt the listener thread.”);
    listener.interrupt();
    webServer = null;
    logger.debug(“Shutdown webserver complete”);
    } else {
    logger.debug(“No webserver to shutdown”);
    }
    } catch (Exception e) {
    logger.error(LoggerCodes.RPC_SERVER_SHUTDOWN_FAILURE, e, LoggerUtility.parameters(“class”,
    e.getClass().getSimpleName(), “message”, e.getMessage()));
    }
    }

    Allow me to translate the comment: “I don’t know how to fix this so I did some bizarre nonsense to break things in a way that works.”

    So, let’s trace through this Java code. It’s not particularly magical, just… a collection of bad ideas.

    The WebServer class has a private field called listener. So, we use getDeclaredField- a reflection method- to get the associated Field object for that private field. Once we have it, we can disable the private protections so that we can use this Field object to peek past the private protections.

    And that’s what we do- we use listenerField.get(webServer) to reach inside of the webServer and fetch its private field. We use set to set that private field to null. Since that listener is a thread, we can simply interrupt() it to break its execution. That is the correct way to stop a thread in Java, which is the first correct thing this code has done.

    As a helpful tip: if you find yourself solving a problem and reach for reflection, you’ve likely misidentified your problem. If you’re using reflection to peek past private protections, you’ve definitely misunderstood your problem.

    [Advertisement]
    ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleSummer Olympics: What IT Teams Need to Do Before & During the Event for Their Businesses
    Next Article Supercharge Your Online Growth With the SEORocket Starter Plan for Just $40

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-48187 – RAGFlow Authentication Bypass

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-26168 – IXON VPN Client Local Privilege Escalation

    Common Vulnerabilities and Exposures (CVEs)

    Path of Exile 2 freezes PC after Windows 11 24H2? Microsoft is looking into it

    Development

    Top 7 Best Open Source Skype Alternatives In 2025

    Linux

    Announcing the Web AI Acceleration Fund

    Development

    Highlights

    How to Make Vape Juice at Home – 100% Accurate Procedure

    January 3, 2025

    Post Content Source: Read More 

    Tesla Cybertruck

    July 10, 2024

    DeepMind’s latest research at ICLR 2023

    May 13, 2025

    These are the top wearable tech products of 2024

    December 30, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.