Feed aggregator
Google DeepMind's AI Systems Can Now Solve Complex Math Problems
Read more of this story at Slashdot.
Adobe Exec Compared Creative Cloud Cancellation Fees To 'Heroin'
Read more of this story at Slashdot.
AI Video Generator Runway Trained On Thousands of YouTube Videos Without Permission
Read more of this story at Slashdot.
Monday Was Hottest Recorded Day on Earth: 'Uncharted Territory'
Read more of this story at Slashdot.
Data Breach Exposes US Spyware Maker Behind Windows, Mac, Android and Chromebook Malware
Read more of this story at Slashdot.
Proposed NASA Budget Cuts Would End Chandra X-Ray Observatory
Read more of this story at Slashdot.
Russia Announces It Will Create Core of New Space Station By 2030
Read more of this story at Slashdot.
CodeSOD: Reflections on Privacy
Jaco's team had a problems with an embedded web server shutting 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.
.comment { border: none; } [Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.Australian Scientists Genetically Engineer Common Fly Species To Eat More of Humanity's Waste
Read more of this story at Slashdot.
Canada Apologizes After Drone Caught Spying On New Zealand's Olympic Practices
Read more of this story at Slashdot.
Cyber Firm KnowBe4 Hired a Fake IT Worker From North Korea
Read more of this story at Slashdot.
World of Warcraft Developers Form Blizzard's Largest and Most Inclusive Union
Read more of this story at Slashdot.
Hugo Awards Organizers Reveal Thousands Spent On Fraudulent Votes To Help One Writer Win
Read more of this story at Slashdot.
GM-Owned Cruise Has Lost Interest In Cars Without Steering Wheels
Read more of this story at Slashdot.
Phish-Friendly Domain Registry '.top' Put On Notice
Read more of this story at Slashdot.
Lawsuit: T-Mobile Must Pay For Breaking Lifetime Price Guarantee
Read more of this story at Slashdot.
Malaysia Asks Microsoft, CrowdStrike To Consider Covering Losses From Global Outage
Read more of this story at Slashdot.
Open Source AI Better for US as China Will Steal Tech Anyway, Zuckerberg Argues
Read more of this story at Slashdot.
A Hacker 'Ghost' Network Is Quietly Spreading Malware on GitHub
Read more of this story at Slashdot.
The AI Job Interviewer Will See You Now
Read more of this story at Slashdot.