Computer
CodeSOD: Concatenated Validation
User inputs are frequently incorrect, which is why we validate them. So, for example, if the user is allowed to enter an "asset ID" to perform some operation on it, we should verify that the asset ID exists before actually doing the operation.
Someone working with Capybara James almost got there. Almost.
private boolean isAssetIdMatching(String requestedAssetId, String databaseAssetId) { return (requestedAssetId + "").equals(databaseAssetId + ""); }This Java code checks if the requestedAssetId, provided by the user, matches a databaseAssetId, fetched from the database. I don't fully understand how we get to this particular function. How is the databaseAssetId fetched? If the fetch were successful, how could it not match? I fear they may do this in a loop across all of the asset IDs in the database until they find a match, but I don't know that for sure, but the naming conventions hint at a WTF.
The weird thing here, though, is the choice to concatenate an empty string to every value. There's no logical reason to do this. It certainly won't change the equality check. I strongly suspect that the goal here was to protect against null values, but it doesn't work that way in Java. If the string variables are null, this will just throw an exception when you try and concatenate.
I strongly suspect the developer was more confident in JavaScript, where this pattern "works".
I don't understand why or how this function got here. I'm not the only one. James writes:
No clue what the original developers were intending with this. It sure was a shocker when we inherited a ton of code like this.
[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.Disney Struggles With How to Use AI - While Retaining Copyrights and Avoiding Legal Issues
Read more of this story at Slashdot.
How Napster Inspired a Generation of Rule-Breaking Entrepreneurs
Read more of this story at Slashdot.
'A Black Hole': America's New Graduates Discover a Dismal Job Market
Read more of this story at Slashdot.
Hyundai's Electric Car Sales Surged 50% Over July 2024
Read more of this story at Slashdot.
Winners Announced in 2025's 'International Obfuscated C Code Competition'
Read more of this story at Slashdot.
N6 (Hexanitrogen) Synthesized for the First Time - Twice As Energy Dense As TNT
Read more of this story at Slashdot.
Vortex's Wireless Take On the Model M Keyboard: Cover Band Or New Legend?
Read more of this story at Slashdot.
The Toughest Programming Question for High School Students on This Year's CS Exam: Arrays
Read more of this story at Slashdot.
China's Government Pushes Real-World AI Use to Jumpstart Its Adoption
Read more of this story at Slashdot.
5 Million People Tried Microsoft's AI Coding Tool 'GitHub Copilot' in the Last 3 Months
Read more of this story at Slashdot.
Nintendo Has Sold Over 6 Million Switch 2s, But Still Can't Keep Up With Demand
Read more of this story at Slashdot.
Did Craigslist Really Kill the Newspaper Industry?
Read more of this story at Slashdot.
Itch.Io Starts Returning the Free Games It Removed From Its Store
Read more of this story at Slashdot.
America's Los Alamos Lab Is Now Investing Heavily In AI For Science
Read more of this story at Slashdot.
Fiverr Ad Mocks Vibe Coding - with a Singing Overripe Avocado
Read more of this story at Slashdot.
Would AI Perform Better If We Simulated Guilt?
Read more of this story at Slashdot.
Despite Breach and Lawsuits, Tea Dating App Surges in Popularity
Read more of this story at Slashdot.
Four Radioactive Wasp Nests Found Near US Nuclear Storage Site
Read more of this story at Slashdot.
AI Tools Gave False Information About Tsunami Advisories
Read more of this story at Slashdot.