Lock 'Em Dead
by in CodeSOD on 2026-08-26Kevin sends us an exception handler from C++. Let's see if we can spot what's going wrong:
catch (Exception::Deadlock)
{
retry;
}
Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.
Kevin sends us an exception handler from C++. Let's see if we can spot what's going wrong:
catch (Exception::Deadlock)
{
retry;
}
Matlab is special. Scientists and researchers love it. Programmers hate it, and not just because it uses 1-based arrays. I've worked on a number of projects where the task was "take this Matlab code and convert it to C so we can run it on an embedded CPU". Somehow, in that process, I've avoided learning much about Matlab.
Andre works on a team that uses Matlab to manage experimental scenarios. They wanted to do a simple task: generate a set of participant-specific images, store them in a database, and reference them later. Somewhere in the intersection of the database product they were using, the Matlab license they had, and other constraints, they discovered that there simply was no good way to do this.
Maciej works as a freelancer, and that frequently means picking up old PHP code that nobody wants to support.
One project had been lingering for ages with key features missing. Specifically, it was supposed to make HTTP requests to other services on an interval, and use that to populate its data. "The old dev tried, but never got it working." It was Maciej's turn to give it a shot.
Eric O was trawling through an API for handling concurrency, and found this little mismatch between the comment and the definition:
/// <summary>
/// private Status, because while this object needs to be able to set the status, consumers should only be able to check it, lest everything break.
/// </summary>
public StatusType Status {
get {
return _status;
}
set {
if (value != _status) {
RaisePropertyChanged("Status");
}
}
}
Frederick A sends us a bit of null checking code, and offers us a better solution.
class ConferenceService
{
/// <summary>
/// Checks if conference is active
/// </summary>
public bool IsCalling()
{
try
{
return m_ConnectionService.Core.State.IsWebRTCConnected;
}
catch
{
return false;
}
}
}
Frequent submitter Capybara James sends us this simple snippet, which highlights that even when you have the lovely convenience of Optional types, you can use them wrong.
if (StringUtils.hasLength(dto.getAssetModelUUID())
// Other conditions
) {
return Optional.ofNullable(dto);
}