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

      Representative Line: Brace Yourself

      September 18, 2025

      Beyond the Pilot: A Playbook for Enterprise-Scale Agentic AI

      September 18, 2025

      GitHub launches MCP Registry to provide central location for trusted servers

      September 18, 2025

      MongoDB brings Search and Vector Search to self-managed versions of database

      September 18, 2025

      Distribution Release: Security Onion 2.4.180

      September 18, 2025

      Distribution Release: Omarchy 3.0.1

      September 17, 2025

      Distribution Release: Mauna Linux 25

      September 16, 2025

      Distribution Release: SparkyLinux 2025.09

      September 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

      AI Momentum and Perficient’s Inclusion in Analyst Reports – Highlights From 2025 So Far

      September 18, 2025
      Recent

      AI Momentum and Perficient’s Inclusion in Analyst Reports – Highlights From 2025 So Far

      September 18, 2025

      Shopping Portal using Python Django & MySQL

      September 17, 2025

      Perficient Earns Adobe’s Real-time CDP Specialization

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

      Valve Survey Reveals Slight Retreat in Steam-on-Linux Share

      September 18, 2025
      Recent

      Valve Survey Reveals Slight Retreat in Steam-on-Linux Share

      September 18, 2025

      Review: Elecrow’s All-in-one Starter Kit for Pico 2

      September 18, 2025

      FOSS Weekly #25.38: GNOME 49 Release, KDE Drama, sudo vs sudo-rs, Local AI on Android and More Linux Stuff

      September 18, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: A Trying Block

    CodeSOD: A Trying Block

    May 22, 2025

    Mark sends us a very simple Java function which has the job of parsing an integer from a string. Now, you might say, “But Java has a built in for that, Integer.parseInt,” and have I got good news for you: they actually used it. It’s just everything else they did wrong.

    <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> <span class="hljs-title function_">makeInteger</span><span class="hljs-params">(String s)</span>
    {
      <span class="hljs-type">int</span> i=<span class="hljs-number">0</span>;
      <span class="hljs-keyword">try</span>
      {
        Integer.parseInt(s);
      }
      <span class="hljs-keyword">catch</span> (NumberFormatException e)
      {
        i=<span class="hljs-number">0</span>;
        <span class="hljs-keyword">return</span> i;
      }
      i=Integer.parseInt(s);
      <span class="hljs-keyword">return</span> i;
    }
    

    This function is really the story of variable i, the most useless variable ever. It’s doing its best, but there’s just nothing for it to do here.

    We start by setting i to zero. Then we attempt to parse the integer, and do nothing with the result. If it fails, we set i to zero again, just for fun, and then return i. Why not just return 0? Because then what would poor i get to do?

    Assuming we didn’t throw an exception, we parse the input again, storing its result in i, and then return i. Again, we treat i like a child who wants to help paint the living room: we give it a dry brush and a section of wall we’re not planning to paint and let it go to town. Nothing it does matters, but it feels like a participant.

    Now, Mark went ahead and refactored this function basically right away, into a more terse and clear version:

    <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> <span class="hljs-title function_">makeInteger</span><span class="hljs-params">(String s)</span>
    {
      <span class="hljs-keyword">try</span>
      {
        <span class="hljs-keyword">return</span> Integer.parseInt(s);
      }
      <span class="hljs-keyword">catch</span> (NumberFormatException e)
      {
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
      }
    }
    

    He went about his development work, and then a few days later came across makeInteger reverted back to its original version. For a moment, he wanted to be mad at someone for reverting his change, but no- this was in an entirely different class. With that information, Mark went and did a search for makeInteger in the code, only to find 39 copies of this function, with minor variations.

    There are an unknown number of copies of the function where the name is slightly different than makeInteger, but a search for Integer.parseInt implies that there may be many more.

    [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 ArticleHand TeX is a handwritten LaTeX symbol classifier
    Next Article Egghead is a simple trivia app

    Related Posts

    News & Updates

    Distribution Release: Security Onion 2.4.180

    September 18, 2025
    News & Updates

    Distribution Release: Omarchy 3.0.1

    September 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-45607 – Itranswarp Authentication Bypass Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Your iPad is getting a major upgrade. Here are the best features in iPadOS 26

    News & Updates

    OpenBSD – multi-platform BSD-based UNIX-like operating system

    Linux

    I tried Google’s new agentic IDE, and it blows away the popular VS Code – here’s how

    News & Updates

    Highlights

    Chrome Vulnerabilities Let Attackers Execute Arbitrary Code – Update Now!

    June 18, 2025

    Chrome Vulnerabilities Let Attackers Execute Arbitrary Code – Update Now!

    Google has released an urgent security update for Chrome browsers across all desktop platforms, addressing critical vulnerabilities that could allow attackers to execute arbitrary code on users’ syste …
    Read more

    Published Date:
    Jun 18, 2025 (2 hours, 54 minutes ago)

    Vulnerabilities has been mentioned in this article.

    Xbox Free Play Days Brings WWE 2K25 & More Titles to Try This Weekend

    July 31, 2025

    Build a conversational natural language interface for Amazon Athena queries using Amazon Nova

    August 13, 2025

    Overwatch 2 shows off its ambitious Stadium Mode, new hero, launch date, and more in the new Season 16 gameplay trailer

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

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