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

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

    +80

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Calendar startCal = Calendar.getInstance();
    startCal.setTime(DateUtils.truncateDateAndTimeToDateOnly(startDate));
    Date strtDt = startCal.getTime();
    
    Calendar endCal = Calendar.getInstance();
    endCal.setTime(DateUtils.truncateDateAndTimeToDateOnly(endDate));
    Date endDt = endCal.getTime();

    Далее по тексту strtDt и endDt используются ровно один раз, startCal и endCal не используются больше вообще. Утилитный метод возвращает требуемый экземпляр класса Date.

    roman-kashitsyn, 21 Ноября 2011

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

    +80

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if((remoteMachineName == null || remoteMachineName == "")){
          result = new Result(false,"Invalid Remote Machine Name..!!");     
        }else{
         CheckOrTerminateProcInstanceTask task = new CheckOrTerminateProcInstanceTask
         (processName, argList, oper,  username, password,remoteMachineName,chkTer,chkTerMatch);
         if (remoteMachineName != null && remoteMachineName.length() > 0) {
         ....
         }else{
         ....
         }
        }

    Суровые индийские проверки

    Desperate, 20 Ноября 2011

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

    +80

    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
    m_scrabblerProperties = Utils.loadPropertiesFile(m_args[1]);
    if (null != m_scrabblerProperties)
    {
    	System.out.println("Executing DBScrubber with properties file " + m_args[1] + " loaded from the classpath");
    }
    else
    {
    	try
    	{
    		m_scrabblerProperties.load(new FileInputStream(m_args[1]));
    		System.out.println("Executing DBScrubber with properties file " + m_args[1] + " loaded from the file system");
    	}
    	catch (IOException e)
    	{
    		System.err.println("Failed to load " + m_args[1] + " from the classpath or the file system");
    	}
    }

    Utils.loadPropertiesFile - какая то хитрая поделуха которая ищет файл в кэше. Если он не найден в кэше, то автор видимо хотел попробовать считать файл с диска, но судя по всему оказался оказался дебилом.

    askell, 18 Ноября 2011

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

    +80

    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
    public static java.util.Date getPreviousMonth () throws ParseException {
            Date currentDate = new Date(System.currentTimeMillis());
            Calendar currentCalendar = Calendar.getInstance();
            currentCalendar.setTimeInMillis(currentDate.getTime());
            
            SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
            //currentCalendar.set(Calendar.MONTH, currentCalendar.get(Calendar.MONTH) - 1);
            currentCalendar.set(Calendar.DAY_OF_MONTH, currentCalendar.get(Calendar.DAY_OF_MONTH) - 30);
            //currentCalendar.set(Calendar.DATE, currentCalendar.getActualMinimum(Calendar.DAY_OF_MONTH));
            format.format(currentCalendar.getTime());
            java.util.Date resultDate = null;
            resultDate = format.parse(format.format(currentCalendar.getTime()));
            return resultDate;
        }

    Занимаюсь рефакторингом. Особо радует предпоследняя строчка.

    MAK, 11 Ноября 2011

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

    +80

    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
    @Deprecated
        private byte getLoByte(int i) {
            byte ret = 0x00;
            String hex = Integer.toHexString(i);
            int length = hex.length();
            if (length == 1) {
                ret = Integer.valueOf(hex.substring(length - 1), 16).byteValue();
            } else if (length >= 2) {
                ret = Integer.valueOf(hex.substring(length - 2), 16).byteValue();
            }
            return ret;
        }
    
        @Deprecated
        private byte getHiByte(int i) {
            String hex = Integer.toHexString(i);
            byte ret = 0x00;
            int length = hex.length();
            if (length > 3) {
                ret = Integer.valueOf(hex.substring(length - 4, length - 2), 16).byteValue();
            } else if (length == 3) {
                ret = Integer.valueOf(hex.substring(length - 3, length - 2), 16).byteValue();
            }
            return ret;
        }

    Вытаскивание старшего и младшего байтов числа из последних одного или двух байтов

    as1an, 01 Ноября 2011

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

    +80

    1. 1
    2. 2
    3. 3
    4. 4
    getBtnContent().setEnabled(enable);
    if (getGridConfig().isContentEnabled()) {
           getBtnContent().setEnabled(enable);
    }

    Программист со стажем, всегда хочет быть уверен что кнопка будет доступна на 150%

    pvtPyle, 22 Октября 2011

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

    +80

    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
    public class Context {
        public int countSuccess;
        public int countFailed;
        // ....
        public void markSuccess() {
            countSuccess++;
            countFailed--;
        }
    
        public void markSuccessAll() {
            countSuccess += countFailed;
            countFailed = 0;
        }   
        // ....
    }

    Вот такая вот супер-абстракция. Пример клиентского кода:

    public void processRequest(Context ctx) {
    // ...
    ctx.countFailed = elems.size();
    for (String elem : elems) {
    boolean success = doSomething(elem);
    if (success) {
    ctx.markSuccess();
    }
    }
    }

    roman-kashitsyn, 12 Октября 2011

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

    +80

    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
    if (k <= 1)
        		{
        			if ((s.equals("2"))||(s.equals("3"))||(s.equals("4")))
        			{
        				txtCommonPeople.setText("ЧЕЛОВЕКА");
        			}
        			else
        			{
        				txtCommonPeople.setText("ЧЕЛОВЕК");
        			}
        		}
        		else
        		{
        				if (s.charAt(k-2) != 1) 
        				{
        					if (((s.charAt(k-1) == 2) || (s.charAt(k-1) == 3) || (s.charAt(k-1) == 4)))
        					{
        						txtCommonPeople.setText("ЧЕЛОВЕКА");
        					}
        					else
        					{
        						txtCommonPeople.setText("ЧЕЛОВЕК");
        					}
        				}
        				else
        				{
        					txtCommonPeople.setText("ЧЕЛОВЕК");
        				}
        		}

    chaoswithin, 26 Сентября 2011

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

    +80

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    try {
    ...
    } catch (Exception ex) {
    	wdComponentAPI.getMessageManager().reportException("ERROR", true);
    }

    Информативно так

    foGa, 12 Августа 2011

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

    +80

    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
    thread = new Thread() {
      @Override 
      public void run() {
        try {
          while( !dataProcessor.isFinished() ) {
            dataProcessor.execute();
            
            Thread.sleep( 60 * 1000L );
          }        
        } catch ( Throwable t ) {
          logger.fatal( "Fatal error in daemon thread", t );
        }
      }
    };
    
    thread.run();

    Вот такое оно параллельное выполнение. Задачка для догадливых.

    galak, 13 Июня 2011

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