1. Лучший говнокод

    В номинации:
    За время:
  2. Java / Говнокод #10338

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (eventInfo.getQuoteList().size() == 0) {
            lineInfo.getEventList().add(eventInfo);
    } else {
            lineInfo.getEventList().add(eventInfo);
    }

    Тебе никуда не деться от добавления!

    arbuzz, 21 Мая 2012

    Комментарии (10)
  3. Java / Говнокод #9926

    +77

    1. 1
    2. 2
    Superclass s = new Subclass();
    ((Subclass)s).useSubclassMethod();

    Чудеса полиморфизма.

    thePooh, 11 Апреля 2012

    Комментарии (14)
  4. Java / Говнокод #9611

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    private String isMasterExecuted(Bundle bl) {
    		String taskName = (String) bl.get("activeTaskName").toString();
    		String isExecuted = "No";
    		if(taskName.equals("Manage")) {
    			isExecuted = "Yes";
    		}
    		return isExecuted;
    	}

    код индийского коллеги. С булевым типом он не знаком.

    zloizerg, 05 Марта 2012

    Комментарии (3)
  5. Java / Говнокод #9203

    +77

    1. 1
    if (!employees.equals("") && employees != null) {

    gorsash, 23 Января 2012

    Комментарии (9)
  6. Java / Говнокод #8142

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static void main(final String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          JFrame.setDefaultLookAndFeelDecorated(false);
          JDialog.setDefaultLookAndFeelDecorated(false);
        } finally {
          new ImageMaps().start();
        }
      }

    НАКОНЕЦ запускаю десктоп-приложение.
    Не знаю как вам, а по мне - выглядит весьма странно.

    Lure Of Chaos, 10 Октября 2011

    Комментарии (153)
  7. Java / Говнокод #7931

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    try {
        order.setAddress(address.clone());
    } catch (CloneNotSupportedException e) {
        // We will not get here, because priorAddressDtoToAdd.address is of Address type.
        // Moreover - none of the subclasses throws this exception
        LOG.error("Address clone is not supported? Nonsense...", e);
    }

    Это было бы даже весело, если бы не повторялось вместе с коментами 3 раза в одном классе.

    roman-kashitsyn, 22 Сентября 2011

    Комментарии (46)
  8. Java / Говнокод #7840

    +77

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    public class SomeServlet extends HttpServlet {
        //...
        private static final int ERROR_NOT_FOUND = 404;
        private static final int ERROR_INTERNAL = 503;
        //...
        protected void doPost(HttpServletRequest req, HttpSerletResponse resp) {
            //...
            if (buff != null) {
                if (buff.length == 0) {
                    resp.sendError(ERROR_INTERNAL);
                }
                //...
            } else {
                resp.sendError(ERROR_NOT_FOUND);
            }
        }
    }

    Велосипедисты взялись за сервлеты.

    roman-kashitsyn, 12 Сентября 2011

    Комментарии (4)
  9. Java / Говнокод #7806

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public abstract class Data {
    		// The tone of Commander Riker's voice makes me suspect that
    		// he is not serious about finding Ambassador T'Pel charming.
    		// My experience suggests that in fact he may mean the exact
    		// opposite of what he says. Irony is a form of expression
    		// I have not yet been able to master.

    lucidfox, 08 Сентября 2011

    Комментарии (31)
  10. Java / Говнокод #7639

    +77

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    @SuppressWarnings("unchecked")
    public void addImage(String key, Bitmap bmp){
    		
    	if(memCache.size() >= MAX_CACHE_SIZE){
    			
    		Object[] array = (Entry[]) cacheUsage.entrySet().toArray();
    			
    		Arrays.sort(array, new Comparator<Object>(){
    				
    			public int compare(Object object1, Object object2) {
    				return (Integer)(((Map.Entry<String, Integer>)object1).getValue()) - 
    						(Integer)(((Map.Entry<String, Integer>)object2).getValue());
    			}
    		});
    			
    		String keyForRemove = ((Map.Entry<String, Integer>)array[0]).getKey();
    		memCache.remove(keyForRemove);
    		cacheUsage.remove(keyForRemove);
    	}
    	
    }

    до чего довело желание всё оптимизацировать

    KoirN, 24 Августа 2011

    Комментарии (20)
  11. Java / Говнокод #7287

    +77

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    public static <T> T createInstance(String className, Object ... ctorParams)
    	{
    		Class<T> type;
    		try {
    			type = (Class <T>) Class.forName(className);
    		} 
    		catch (ClassNotFoundException e) { throw new RuntimeException(e); }
    		
    		Class <?> [] paramTypes = new Class [ctorParams.length];
    		for(int i = 0; i < ctorParams.length; i ++)
    			paramTypes[i] = (Class <?>) ctorParams[i].getClass();
    		
    		Constructor<T> ctor;
    		try {
    			ctor = type.getConstructor(paramTypes);
    		} 
    		catch (SecurityException e)    { throw new RuntimeException(e); }
    		catch (NoSuchMethodException e){ throw new RuntimeException(e); }
    		
    		T instance;
    		try {
    			instance = ctor.newInstance(ctorParams);
    		} 
    		catch (IllegalArgumentException e)  { throw new RuntimeException(e); }
    		catch (InstantiationException e)    { throw new RuntimeException(e); }
    		catch (IllegalAccessException e)    { throw new RuntimeException(e); }
    		catch (InvocationTargetException e) { throw new RuntimeException(e); }
    		
    		return instance;
    	}

    Тут само Java вынуждает говнокодить. О святая простота!

    dveyarangi, 19 Июля 2011

    Комментарии (69)