Click here to Skip to main content
15,885,366 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Extension Methods Pin
Richard Deeming19-Jul-13 8:55
mveRichard Deeming19-Jul-13 8:55 
GeneralRe: Extension Methods Pin
Lutosław19-Jul-13 9:06
Lutosław19-Jul-13 9:06 
GeneralRe: Extension Methods Pin
PIEBALDconsult19-Jul-13 8:09
mvePIEBALDconsult19-Jul-13 8:09 
GeneralRe: Message Automatically Removed Pin
lewax0019-Jul-13 9:35
lewax0019-Jul-13 9:35 
GeneralRe: Message Automatically Removed Pin
ZurdoDev19-Jul-13 10:22
professionalZurdoDev19-Jul-13 10:22 
GeneralRe: Message Automatically Removed Pin
lewax0021-Jul-13 11:03
lewax0021-Jul-13 11:03 
GeneralRe: Message Automatically Removed Pin
pkfox29-Jul-13 22:26
professionalpkfox29-Jul-13 22:26 
GeneralThis one is for the Java experts Pin
Dennis_E18-Jul-13 0:56
professionalDennis_E18-Jul-13 0:56 
I bumped into this Java code in a project I'm supposed to 'make work correctly'.
Every method in the class works like this. (userBase checks if the user with the given email is allowed to execute the action and then fetched stuff out of the database.)
How many weird things can you spot? It's not hilarious or something, just weird.

Java
public class Controller
{
    //Lots of other methods left out...

    public User getUserByID(String email, long id) throws Exception
    {
        final ObjectHolder<User> userHolder = new ObjectHolder();
        final AtomicBoolean done = new AtomicBoolean(false);

        userBase.handleAction(email, new GetUserByIDAction(), new GetUserByIDActionExecutionDetails(id), new IActionListener<User>()
        {
            @Override
            public void actionFinished(User user) throws Exception
            {
                synchronized (done)
                {
                    userHolder.set(user);
                    done.set(true);
                    done.notifyAll();
                }
            }

            @Override
            public void exception(Exception exception) throws Exception
            {
                synchronized (done)
                {
                    done.set(true);
                    done.notifyAll();
                    throw exception;
                }
            }
        });
        
        synchronized (done)
        {
            while (!done.get()) {
                done.wait(100);
            }

            if (userHolder.get() == null) {
                throw new UserNotFoundException(id);
            } else {
                return userHolder.get();
            }
        }
    }
    
    private class ObjectHolder<T>
    {
        private T t;
        
        public ObjectHolder(T t)
        {
            set(t);
        }
        
        public void set(T t)
        {
            this.t = t;
        }
        
        public T get()
        {
            return t;
        }
    }

}

GeneralRe: This one is for the Java experts Pin
Nagy Vilmos18-Jul-13 1:52
professionalNagy Vilmos18-Jul-13 1:52 
GeneralRe: This one is for the Java experts Pin
Fredrik Bornander18-Jul-13 2:10
professionalFredrik Bornander18-Jul-13 2:10 
GeneralRe: This one is for the Java experts Pin
Dennis_E18-Jul-13 2:27
professionalDennis_E18-Jul-13 2:27 
GeneralRe: This one is for the Java experts Pin
Nagy Vilmos18-Jul-13 3:54
professionalNagy Vilmos18-Jul-13 3:54 
GeneralRe: This one is for the Java experts Pin
svella23-Jul-13 3:57
svella23-Jul-13 3:57 
GeneralRe: This one is for the Java experts Pin
Brisingr Aerowing18-Jul-13 6:40
professionalBrisingr Aerowing18-Jul-13 6:40 
GeneralRe: This one is for the Java experts Pin
AlphaDeltaTheta18-Jul-13 15:53
AlphaDeltaTheta18-Jul-13 15:53 
GeneralRe: This one is for the Java experts Pin
ExcellentOrg22-Jul-13 21:30
ExcellentOrg22-Jul-13 21:30 
GeneralRe: This one is for the Java experts Pin
englebart23-Jul-13 2:57
professionalenglebart23-Jul-13 2:57 
GeneralTasks and stack traces... Pin
Dave Kreskowiak17-Jul-13 7:18
mveDave Kreskowiak17-Jul-13 7:18 
GeneralRe: Tasks and stack traces... Pin
Nagy Vilmos17-Jul-13 9:24
professionalNagy Vilmos17-Jul-13 9:24 
GeneralRe: Tasks and stack traces... Pin
Dave Kreskowiak17-Jul-13 9:34
mveDave Kreskowiak17-Jul-13 9:34 
GeneralRe: Tasks and stack traces... Pin
Nagy Vilmos17-Jul-13 10:02
professionalNagy Vilmos17-Jul-13 10:02 
GeneralRe: Tasks and stack traces... Pin
Dave Kreskowiak17-Jul-13 10:23
mveDave Kreskowiak17-Jul-13 10:23 
GeneralEpic Visual Studios "No Code" Pin
Rain Dancer17-Jul-13 1:09
Rain Dancer17-Jul-13 1:09 
GeneralRe: Epic Visual Studios "No Code" PinPopular
Argonia17-Jul-13 1:12
professionalArgonia17-Jul-13 1:12 
GeneralRe: Epic Visual Studios "No Code" Pin
Nicholas Marty17-Jul-13 1:41
professionalNicholas Marty17-Jul-13 1:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.