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

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 6, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 6, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 6, 2025

      In MCP era API discoverability is now more important than ever

      June 5, 2025

      Black Myth: Wukong is coming to Xbox exactly one year after launching on PlayStation

      June 6, 2025

      Reddit wants to sue Anthropic for stealing its data, but the Claude AI manufacturers vow to “defend ourselves vigorously”

      June 6, 2025

      Satya Nadella says Microsoft makes money every time you use ChatGPT: “Every day that ChatGPT succeeds is a fantastic day”

      June 6, 2025

      Multiple reports suggest a Persona 4 Remake from Atlus will be announced during the Xbox Games Showcase

      June 6, 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

      TC39 advances numerous proposals at latest meeting

      June 6, 2025
      Recent

      TC39 advances numerous proposals at latest meeting

      June 6, 2025

      TypeBridge – zero ceremony, compile time rpc for client and server com

      June 6, 2025

      Simplify Cloud-Native Development with Quarkus Extensions

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

      Black Myth: Wukong is coming to Xbox exactly one year after launching on PlayStation

      June 6, 2025
      Recent

      Black Myth: Wukong is coming to Xbox exactly one year after launching on PlayStation

      June 6, 2025

      Reddit wants to sue Anthropic for stealing its data, but the Claude AI manufacturers vow to “defend ourselves vigorously”

      June 6, 2025

      Satya Nadella says Microsoft makes money every time you use ChatGPT: “Every day that ChatGPT succeeds is a fantastic day”

      June 6, 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:

    try {
    		ps = conn.prepareStatement(SQL_GET_LOT_WORKUP_STATUSES);
    		ps.setLong(1, _lotId);
    
    		rs = ps.executeQuery();
    
    		while (rs.next()) {
    				result.add(new Integer(rs.getInt(1)));
    		}
    }
    finally {
    		CloseUtil.close(ps,rs);
    }
    
    // instatiate a the array
    _workupStatuses = new int[result.size()];
    
    // convert the integers to ints
    for (int h=0; 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

    Black Myth: Wukong is coming to Xbox exactly one year after launching on PlayStation

    June 6, 2025
    News & Updates

    Reddit wants to sue Anthropic for stealing its data, but the Claude AI manufacturers vow to “defend ourselves vigorously”

    June 6, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-46329 – Snowflake libsnowflakeclient Sensitive Information Logging

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-46190 – SourceCodester Client Database Management System SQL Injection

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-31263 – Apple macOS Coprocessor Memory Corruption

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-20994 – Samsung Internet File Access Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Development

    AI21 Labs Jamba-Instruct model is now available in Amazon Bedrock

    June 25, 2024

    We are excited to announce the availability of the Jamba-Instruct large language model (LLM) in…

    Once Human FAQ: Release date, platforms, price, and other questions answered

    July 4, 2024

    One simple feature would greatly improve Steam Deck 2, ROG Ally 2, and other next-gen PC gaming handhelds for everyone

    May 16, 2025

    Scaling Reinforcement Learning Beyond Math: Researchers from NVIDIA AI and CMU Propose Nemotron-CrossThink for Multi-Domain Reasoning with Verifiable Reward Modeling

    May 5, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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