37

Today I found three user profile pages on Stack Overflow which throw an error, however, their respective meta counterparts still work, as do the rest of their network profiles.

Comments from our resident ninja puppy suggest that with moderator status it is still possible to view those profiles.

Further comments by another ninja suggest that indeed the profile page is broken, as well as the Developer Story, as the activity tab and others still function.

Why are these profiles broken and can they be fixed?

19

1 Answer 1

20

We were cleaning up some old cruft related to work history that could be used to populate the Job Title shown below your username:

Current Position, formerly in the profile editor

This whole section was kinda redundant / unnecessary, and caused some amount of confusion:

As part of this, we've done a bit of refactoring for the logic that uses this data - specifically, a method that tries to format a title from some combination of the Role, Description and Organization fields that might have been populated from that form. This method originally lived in the Razor view that implements that part of the user page, and deftly avoided problems by using this handy extension method named IsEmpty().

That method was moved to a normal CS file, at which point that extension method was no longer available by default. That should have broken the build (and would never have been committed), but it turns out we have a different extension method floating around our codebase...

public static bool IsEmpty<T>(this IEnumerable<T> collection) => !collection.Any();

That's very different logic from what StringExtensions.IsEmpty() provides - critically, it doesn't cleanly handle a NULL parameter. But, since String implements IEnumerable, the compiler happily substituted the new extension method for the old and the build completed without complaint. All was well... Unless anyone ever happened to have a NULL value for one of the work history fields.

And they were null on those profiles.

The logic now checks for null explicitly, doesn't call any methods named IsEmpty(), and should therefore proceed cleanly as we continue stripping out this old logic. Hat-tip to Dean Ward for jumping in to fix it!

2
  • 3
    Do I understand this to suggest that you’re getting rid of “Just Less-Than-Three Code”? Also, excellent evidence for why extension methods are evil, especially when given generic names and using base types.
    – Cody Gray Mod
    Commented Apr 25, 2019 at 20:25
  • Yeah, that should be gone now @cody
    – Shog9
    Commented Apr 26, 2019 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .