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

      Designing For TV: Principles, Patterns And Practical Guidance (Part 2)

      September 5, 2025

      Neo4j introduces new graph architecture that allows operational and analytics workloads to be run together

      September 5, 2025

      Beyond the benchmarks: Understanding the coding personalities of different LLMs

      September 5, 2025

      Top 10 Use Cases of Vibe Coding in Large-Scale Node.js Applications

      September 3, 2025

      Building smarter interactions with MCP elicitation: From clunky tool calls to seamless user experiences

      September 4, 2025

      From Zero to MCP: Simplifying AI Integrations with xmcp

      September 4, 2025

      Distribution Release: Linux Mint 22.2

      September 4, 2025

      Coded Smorgasbord: Basically, a Smorgasbord

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

      Drupal 11’s AI Features: What They Actually Mean for Your Team

      September 5, 2025
      Recent

      Drupal 11’s AI Features: What They Actually Mean for Your Team

      September 5, 2025

      Why Data Governance Matters More Than Ever in 2025?

      September 5, 2025

      Perficient Included in the IDC Market Glance for Digital Business Professional Services, 3Q25

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

      How DevOps Teams Are Redefining Reliability with NixOS and OSTree-Powered Linux

      September 5, 2025
      Recent

      How DevOps Teams Are Redefining Reliability with NixOS and OSTree-Powered Linux

      September 5, 2025

      Distribution Release: Linux Mint 22.2

      September 4, 2025

      ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

      September 4, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Integral to a Database Read

    CodeSOD: Integral to a Database Read

    June 5, 2025

    One of the key points of confusion for people unfamiliar with Java is the distinction between true object types, like Integer, and “primitive” types, like int. This is made worse by the collection types, like ArrayList, which needs to hold a true object type, but can’t hold a primitive. A generic ArrayList<Integer> is valid, but ArrayList<int> won’t compile. Fortunately for everyone, Java automatically “boxes” types- at least since Java 5, way back in 2004- so integerList.add(5) and int n = integerList.get(0) will both work just fine.

    Somebody should have told that to Alice‘s co-worker, who spends a lot of code to do some type gymnastics that they shouldn’t have:

    <span class="hljs-keyword">try</span> {
    		ps = conn.prepareStatement(SQL_GET_LOT_WORKUP_STATUSES);
    		ps.setLong(<span class="hljs-number">1</span>, _lotId);
    
    		rs = ps.executeQuery();
    
    		<span class="hljs-keyword">while</span> (rs.next()) {
    				result.add(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Integer</span>(rs.getInt(<span class="hljs-number">1</span>)));
    		}
    }
    <span class="hljs-keyword">finally</span> {
    		CloseUtil.close(ps,rs);
    }
    
    <span class="hljs-comment">// instatiate a the array</span>
    _workupStatuses = <span class="hljs-keyword">new</span> <span class="hljs-title class_">int</span>[result.size()];
    
    <span class="hljs-comment">// convert the integers to ints</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> h=<span class="hljs-number">0</span>; h<result.size(); h++) {
    		_workupStatuses[h] = ((Integer)result.get(h)).intValue();
    }
    

    This runs a query against the database, and then iterates across the result to populate a List type with integers, and right away we’re getting into confused territory. rs.getInt returns an int primitive, which they manually box with new Integer, and stuff into the List. And look, I wouldn’t really call that a WTF, but it’s what they do next that leaves me scratching my head.

    They initialize a private member, _workupStatuses to a new array of ints. Then they copy every integer from the result collection into the array, first by casting the get return value to Integer, then by pulling off the intValue.

    In the end, this whole dance happens because Java ResultSet types open cursors on the database side and thus don’t have the capacity to tell you how many rows they returned. You need to iterate across each record until it runs out of results. That’s why they populate an intermediate list. Then they can check the size and create an array, but that itself is a big why. I’m not going to say that using arrays in Java is an instant anti-pattern, but it’s always something to be suspicious of, especially when you’re holding result sets. It’s probably a premature optimization: the key performance distance is on insertions where an ArrayList may need to resize and copy its internal backing store.

    My suspicion, however, is that this code falls into the category of “C programmer forced to do Java”. They’re comfortable with an array of integers, which is covers 90% of the data types you use in C but a dynamic, complicated data structure is horrifying to them. So they use it when they absolutely have to, and then throw it away as quickly as they can to get back to what they’re familiar with.

    [Advertisement] Plan Your .NET 9 Migration with Confidence
    Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFOSS Weekly #25.23: Helwan Linux, Quarkdown, Konsole Tweaks, Keyboard Shortcuts and More Linux Stuff
    Next Article FuguIta is a live system based on the OpenBSD operating system

    Related Posts

    News & Updates

    Building smarter interactions with MCP elicitation: From clunky tool calls to seamless user experiences

    September 4, 2025
    News & Updates

    From Zero to MCP: Simplifying AI Integrations with xmcp

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

    CVE-2025-34119 – EasyCafe Server Remote File Disclosure

    Common Vulnerabilities and Exposures (CVEs)

    Sony quietly lifts region locks on PC games—but not for everything

    Operating Systems

    AI-First Transformation Strategy Unfolds at the 3M Open

    Development

    Celebrating an academic-industry collaboration to advance vehicle technology

    Artificial Intelligence

    Highlights

    CVE-2025-48493 – “Redis AUTH Credentials Exposed in Yii Logs”

    June 5, 2025

    CVE ID : CVE-2025-48493

    Published : June 5, 2025, 5:15 p.m. | 1 hour, 13 minutes ago

    Description : The Yii 2 Redis extension provides the redis key-value store support for the Yii framework 2.0. On failing connection, the extension writes commands sequence to logs. Prior to version 2.0.20, AUTH parameters are written in plain text exposing username and password. That might be an issue if attacker has access to logs. Version 2.0.20 fixes the issue.

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Well done, EA — what may be Battlefield 2042’s final update made me more excited than ever for Battlefield 6

    August 24, 2025

    CVE-2025-46252 – Contact Form 7 SQL Injection Vulnerability

    April 22, 2025

    Keep Your Place: Enhancing User Experience with Fragment Method

    June 11, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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