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

      CodeSOD: Identify a Nap

      September 23, 2025

      Ambient Animations In Web Design: Principles And Implementation (Part 1)

      September 23, 2025

      Benchmarking AI-assisted developers (and their tools) for superior AI governance

      September 23, 2025

      Digital.ai launches White-box Cryptography Agent to enable stronger application security

      September 23, 2025

      Development Release: MX Linux 25 Beta 1

      September 22, 2025

      DistroWatch Weekly, Issue 1140

      September 21, 2025

      Distribution Release: DietPi 9.17

      September 21, 2025

      Development Release: Zorin OS 18 Beta

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

      Stop using .reverse().find(): meet findLast()

      September 23, 2025
      Recent

      Stop using .reverse().find(): meet findLast()

      September 23, 2025

      @ts-ignore is almost always the worst option

      September 22, 2025

      MutativeJS v1.3.0 is out with massive performance gains

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

      How I Configure Polybar to Customize My Linux Desktop

      September 23, 2025
      Recent

      How I Configure Polybar to Customize My Linux Desktop

      September 23, 2025

      Development Release: MX Linux 25 Beta 1

      September 22, 2025

      DistroWatch Weekly, Issue 1140

      September 21, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Objectifying Yourself

    CodeSOD: Objectifying Yourself

    April 28, 2025

    “Boy, stringly typed data is hard to work with. I wish there were some easier way to work with it!”

    This, presumably, is what Gary‘s predecessor said. Followed by, “Wait, I have an idea!”

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Object <span class="hljs-title function_">createValue</span><span class="hljs-params">(String string)</span> {
    	<span class="hljs-type">Object</span> <span class="hljs-variable">value</span> <span class="hljs-operator">=</span> parseBoolean(string);
    	<span class="hljs-keyword">if</span> (value != <span class="hljs-literal">null</span>) {
    		<span class="hljs-keyword">return</span> value;
    	}
    
    	value = parseInteger(string);
    	<span class="hljs-keyword">if</span> (value != <span class="hljs-literal">null</span>) {
    		<span class="hljs-keyword">return</span> value;
    	}
    
    	value = parseDouble(string);
    	<span class="hljs-keyword">if</span> (value != <span class="hljs-literal">null</span>) {
    		<span class="hljs-keyword">return</span> value;
    	}
    
    	<span class="hljs-keyword">return</span> string;
    }
    

    This takes a string, and then tries to parse it, first into a boolean, failing that into an integer, and failing that into a double. Otherwise, it returns the original string.

    And it returns an object, which means you still get to guess what’s in there even after this. You just get to guess what it returned, and hope you cast it to the correct type. Which means this almost certainly is called like this:

    <span class="hljs-type">boolean</span> <span class="hljs-variable">myBoolField</span> <span class="hljs-operator">=</span> (Boolean)createValue(someStringContainingABool);
    

    Which makes the whole thing useless, which is fun.

    Gary found this code in a “long since abandoned” project, and I can’t imagine why it ended up getting abandoned.

    [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 ArticleDual Booting CachyOS and Windows
    Next Article CVE-2025-4006 – Youyiio BeyongCms Unrestricted File Upload Vulnerability

    Related Posts

    News & Updates

    Development Release: MX Linux 25 Beta 1

    September 22, 2025
    News & Updates

    DistroWatch Weekly, Issue 1140

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

    This massive Samsung TV is an Xbox — and it’s cheaper than a Series X in Best Buy’s anti-Prime Day sale

    News & Updates

    Meta Rejects EU’s AI Code, Warns It Could Hurt Innovation

    Operating Systems

    CVE-2025-5944 – Elementor Element Pack Addons Stored Cross-Site Scripting

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-52826 – UXPER Sala Object Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Microsoft to stop pushing older Windows 11 drivers through Windows Update

    June 20, 2025

    Windows Update will no longer offer older legacy drivers when a newer replacement driver is…

    CVE-2025-46707 – VMware ESXi Firmware Privilege Escalation

    June 27, 2025

    Camera’s PTZOptics en ValueHD via hardcoded wachtwoord over te nemen

    June 13, 2025

    Soup-of-Experts: Pretraining Specialist Models via Parameters Averaging

    July 4, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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