Skip to main content

Intern had no idea what not to do, so nearly mangled a mainframe

3 weeks 4 days ago
An early career lesson in the power of documentation, and the importance of exploration

Who, Me?  The Register has very few rules, but one we always observe on a Monday morning is to present a new installment of Who, Me? – the reader-contributed column in which you share stories of breaking the rules, without breaking your career in the process.…

Simon Sharwood

CodeSOD: Contracting Space

3 weeks 4 days ago

A ticket came in marked urgent. When users were entering data in the header field, the spaces they were putting in kept getting mangled. This was in production, and had been in production for sometime.

Mike P picked up the ticket, and was able to track down the problem to a file called Strings.java. Yes, at some point, someone wrote a bunch of string helper functions and jammed them into a package. Of course, many of the functions were re-implementations of existing functions: reinvented wheels, now available in square.

For example, the trim function.

/** * @param str * @return The trimmed string, or null if the string is null or an empty string. */ public static String trim(String str) { if (str == null) { return null; } String ret = str.trim(); int len = ret.length(); char last = '\u0021'; // choose a character that will not be interpreted as whitespace char c; StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i++) { c = ret.charAt(i); if (c > '\u0020') { if (last <= '\u0020') { sb.append(' '); } sb.append(c); } last = c; } ret = sb.toString(); if ("".equals(ret)) { return null; } else { return ret; } }

Now, Mike's complaint is that this function could have been replaced with a regular expression. While that would likely be much smaller, regexes are expensive- in performance and frequently in cognitive overhead- and I actually have no objections to people scanning strings.

But let's dig into what we're doing here.

They start with a null check, which sure. Then they trim the string; never a good sign when your homemade trim method calls the built-in.

Then, they iterate across the string, copying characters into a StringBuffer. If the current character is above unicode character 20- the realm of printable characters- and if the last character was a whitespace character, we copy a whitespace character into the output, and then the printable character into the output.

What this function does is simply replace runs of whitespace with single whitespace characters.

"This string" becomes "This string"

Badly I should add. Because there are plenty of whitespace characters which appear above \u0020- like the non-breaking space (\u00A0), and many other control characters. While you might be willing to believe your users will never figure out how to type those, you can't guarantee that they'll never copy/paste them.

For me, however, this function does something far worse than being bad at removing extraneous whitespace. Because it has that check at the end- if I handed it a perfectly good string that is only whitespace, it hands me back a null.

I can see the argument- it's a bad input, so just give me back an objectively bad result. No IsNullOrEmpty check, just a simple null check. But I still hate it- turning an actual value into a null just bothers me, and seems like an easy way to cause problems.

In any case, the root problem with this bug was simply developer invented requirements: the users never wanted stray spaces to be automatically removed in the middle of the string. Trimmed yes, gutted no.

No one tried to use multiple spaces for most of the history of the application, thus no one noticed the problem. No one expected it to not work. Hence the ticket and the panic by users who didn't understand what was going on.

.comment { border: none; } [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.
Remy Porter

NASA administrator says US should have ‘village’ on Moon in a decade

3 weeks 4 days ago
The Register is at the world’s biggest space gabfest and just heard the world's top 6 space agency leaders speak

IAC 2025  If the USA’s space strategy succeeds, it will run a “village” on the moon in a decade, NASA administrator Sean Duffy told the International Aeronautical Congress (IAC) in Sydney today.…

Simon Sharwood

AI-Powered Stan Lee Hologram Debuts at LA Comic Con

3 weeks 4 days ago
An anonymous reader shared this report from Ars Technica: Late last week, The Hollywood Reporter ran a story about an "AI Stan Lee hologram" that would be appearing at the LA Comic Con this weekend. [Watch it in action here.] Nearly seven years after the famous Marvel Comics creator's death at the age of 95, fans will be able to pay $15 to $20 this weekend to chat with a life-sized, AI-powered avatar of Lee in an enclosed booth at the show. The instant response from many fans and media outlets to the idea was not kind, to say the least. A writer for TheGamer called the very idea "demonic" and said we need to "kill it with fire before it's too late...." But Chris DeMoulin, the CEO of the parent company behind LA Comic Con, urged critics to come see the AI-powered hologram for themselves before rushing to judgment. "We're not afraid of people seeing it and we're not afraid of criticism," he told Ars. "I'm just a fan of informed criticism, and I think most of what's been out there so far has not really been informed...." [DeMoulin said he saw] "the leaps and bounds that they were making in improving the technology, improving the interactivity." Now, he said, it's possible to create an AI-powered version that ingests "all of the actual comments that people made during their life" to craft an interactive hologram that "is not literally quoting the person, but everything it was saying was based on things that person actually said...." [Hyperreal CEO and Chief Architect Remington Scott] said Hyperreal "can't share specific technical details" of the models or training techniques they use to power these recreations. But Scott added that this training project is "particularly meaningful, [because] Stan Lee had actually begun digitizing himself while he was alive, with the vision of creating a digital double so his fans could interact with him on a larger scale...." Still, DeMoulin said he understands why the idea of using even a stylized version of Lee's likeness in this manner could rub some fans the wrong way. "When a new technology comes out, it just feels wrong to them, and I respect the fact that this feels wrong to people," he said. "I totally agree that something like this-not just for Stan but for anyone, any celebrity alive or dead-could be put into this technology and used in a way that would be exploitative and unfortunate." That's why DeMoulin said he and the others behind the AI-powered Lee feel a responsibility "to make sure that if we were going to do this, we never got anywhere close to that." The "premium, authenticated digital identities" created by Hyperreal's system are "not replacing artists," says Hyperreal CEO/Chief Architect Remington Scott, but "creating respectful digital extensions that honor their legacy." Still, DeMoulin says in the article that "I suppose if we do it and thousands of fans interact with [it] and they don't like it, we'll stop doing it."

Read more of this story at Slashdot.

EditorDavid