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

      The state of DevOps and AI: Not just hype

      September 1, 2025

      A Breeze Of Inspiration In September (2025 Wallpapers Edition)

      August 31, 2025

      10 Top Generative AI Development Companies for Enterprise Node.js Projects

      August 30, 2025

      Prompting Is A Design Act: How To Brief, Guide And Iterate With AI

      August 29, 2025

      Look out, Meta Ray-Bans! These AI glasses just raised over $1M in pre-orders in 3 days

      September 2, 2025

      Samsung ‘Galaxy Glasses’ powered by Android XR are reportedly on track to be unveiled this month

      September 2, 2025

      The M4 iPad Pro is discounted $100 as a last-minute Labor Day deal

      September 2, 2025

      Distribution Release: Linux From Scratch 12.4

      September 1, 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

      Enhanced Queue Job Control with Laravel’s ThrottlesExceptions failWhen() Method

      September 2, 2025
      Recent

      Enhanced Queue Job Control with Laravel’s ThrottlesExceptions failWhen() Method

      September 2, 2025

      August report 2025

      September 2, 2025

      Fake News Detection using Python Machine Learning (ML)

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

      Installing Proxmox on a Raspberry Pi to run Virtual Machines on it

      September 2, 2025
      Recent

      Installing Proxmox on a Raspberry Pi to run Virtual Machines on it

      September 2, 2025

      Download Transcribe! for Windows

      September 1, 2025

      Microsoft Fixes CertificateServicesClient (CertEnroll) Error in Windows 11

      September 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Format Identified

    CodeSOD: Format Identified

    May 28, 2025

    Many nations have some form of national identification number, especially around taxes. Argentina is no exception.

    Their “CUIT” (Clave Única de Identificación Tributaria) and “CUIL” (Código Único de Identificación Laboral) are formatted as “##-########-#”.

    Now, as datasets often don’t store things in their canonical representation, Nick‘s co-worker was given a task: “given a list of numbers, reformat them to look like CUIT/CUIL. That co-worker went off for five days, and produced this Java function.

    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">normalizarCuitCuil</span><span class="hljs-params">(String cuitCuilOrigen)</span>{
    	<span class="hljs-type">String</span> <span class="hljs-variable">valorNormalizado</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>();
    	
    	<span class="hljs-keyword">if</span> (cuitCuilOrigen == <span class="hljs-literal">null</span> || <span class="hljs-string">""</span>.equals(cuitCuilOrigen) || cuitCuilOrigen.length() < MINIMA_CANTIDAD_ACEPTADA_DE_CARACTERES_PARA_NORMALIZAR){
    		valorNormalizado = <span class="hljs-string">""</span>;
    	}<span class="hljs-keyword">else</span>{
    		<span class="hljs-type">StringBuilder</span> <span class="hljs-variable">numerosDelCuitCuil</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">StringBuilder</span>(<span class="hljs-number">13</span>);
    		cuitCuilOrigen = cuitCuilOrigen.trim();
    		
    		<span class="hljs-comment">// Se obtienen solo los números:</span>
    		<span class="hljs-type">Matcher</span> <span class="hljs-variable">buscadorDePatron</span> <span class="hljs-operator">=</span>  patternNumeros.matcher(cuitCuilOrigen);
    		<span class="hljs-keyword">while</span> (buscadorDePatron.find()){
    			numerosDelCuitCuil.append(buscadorDePatron.group());
    		}
    		
    		<span class="hljs-comment">// Se le agregan los guiones:</span>
    		valorNormalizado = numerosDelCuitCuil.toString().substring(<span class="hljs-number">0</span>,<span class="hljs-number">2</span>) 
    							+ <span class="hljs-string">"-"</span>
    							+ numerosDelCuitCuil.toString().substring(<span class="hljs-number">2</span>,numerosDelCuitCuil.toString().length()-<span class="hljs-number">1</span>) 
    							+ <span class="hljs-string">"-"</span>
    							+ numerosDelCuitCuil.toString().substring(numerosDelCuitCuil.toString().length()-<span class="hljs-number">1</span>, numerosDelCuitCuil.toString().length());
    		
    	}
    	<span class="hljs-keyword">return</span> valorNormalizado;
    }
    

    We start with a basic sanity check that the string exists and is long enough. If it isn’t, we return an empty string, which already annoys me, because an empty result is not a good way to communicate “I failed to parse”.

    But assuming we have data, we construct a string builder and trim whitespace. And already we have a problem: we already validated that the string was long enough, but if the string contained more trailing whitespace than a newline, we’re looking at a problem. Now, maybe we can assume the data is good, but the next line implies that we can’t rely on that- they create a regex matcher to identify numeric values, and for each numeric value they find, they append it to our StringBuilder. This implies that the string may contain non-numeric values which need to be rejected, which means our length validation was still wrong.

    So either the data is clean and we’re overvalidating, or the data is dirty and we’re validating in the wrong order.

    But all of that’s a preamble to a terrible abuse of string builders, where they discard all the advantages of using a StringBuilder by calling toString again and again and again. Now, maybe the function caches results or the compiler can optimize it, but the result is a particularly unreadable blob of slicing code.

    Now, this is ugly, but at least it works, assuming the input data is good. It definitely should never pass a code review, but it’s not the kind of bad code that leaves one waking up in the middle of the night in a cold sweat.

    No, what gets me about this is that it took five days to write. And according to Nick, the responsible developer wasn’t just slacking off or going to meetings the whole time, they were at their desk poking at their Java IDE and looking confused for all five days.

    And of course, because it took so long to write the feature, management didn’t want to waste more time on kicking it back via a code review. So voila: it got forced through and released to production since it passed testing.

    [Advertisement]
    Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticlePanda3DS is an Nintendo 3DS emulator
    Next Article CVE-2025-5082 – “WordPress WP Attachments Reflected Cross-Site Scripting Vulnerability”

    Related Posts

    News & Updates

    Look out, Meta Ray-Bans! These AI glasses just raised over $1M in pre-orders in 3 days

    September 2, 2025
    News & Updates

    Samsung ‘Galaxy Glasses’ powered by Android XR are reportedly on track to be unveiled this month

    September 2, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    FunSearch: Making new discoveries in mathematical sciences using Large Language Models

    Artificial Intelligence

    Cppcheck – static analysis tool

    Linux

    CVE-2025-7539 – Code-projects Online Appointment Booking System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    How to get started with Markdown in the Notepad app for Windows 11

    News & Updates

    Highlights

    Development

    Log Framework Integration in Azure Functions with Azure Cosmos DB

    April 2, 2025

    Introduction Logging is an essential part of application development, especially in cloud environments where monitoring…

    “GPT4o’s update is absurdly dangerous to release to a billion active users”: Even OpenAI CEO Sam Altman admits ChatGPT is “too sycophant-y,” but a fix is on the way

    April 29, 2025

    Launch a Startup with $0 Investment: AI Blueprint Inside

    July 3, 2025

    Exploring the Sparse Frontier: How Researchers from Edinburgh, Cohere, and Meta Are Rethinking Attention Mechanisms for Long-Context LLMs

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

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