1. Список говнокодов пользователя someone

    Всего: 116

  2. C# / Говнокод #11419

    +118

    1. 1
    2. 2
    decimal retValue = <...>
    var span = TimeSpan.FromMinutes(double.Parse(retValue.ToString()));

    Почему бы просто не (double) retValue...

    someone, 15 Июля 2012

    Комментарии (2)
  3. SQL / Говнокод #11416

    −134

    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
    SELECT     ISNULL(SUM(dbo.colors.setup_time_base + dbo.colors.setup_time_add), 0) AS setup_time, ISNULL(SUM(dbo.colors.setup_time_base), 0) AS setup_time_base, 
                          ISNULL(SUM(dbo.colors.setup_time_add), 0) AS setup_time_add, ISNULL(SUM(dbo.colors.setup_length_base), 0) + 40 AS setup_lenght_base, 
                          ISNULL(SUM(dbo.colors.setup_lenght_add), 0) AS setup_lenght_add, ISNULL(SUM(dbo.colors.setup_length_base + dbo.colors.setup_lenght_add), 0) 
                          + 40 AS setup_lenght, ISNULL(COUNT(dbo.dir_order_sections.color_id), 0) AS section_count, CASE WHEN COUNT(dbo.dir_order_sections.color_id) 
                          = 0 THEN 0.5 WHEN COUNT(dbo.dir_order_sections.color_id) >= 1 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 2 THEN 0.65 WHEN COUNT(dbo.dir_order_sections.color_id) >= 3 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 6 THEN 1 WHEN COUNT(dbo.dir_order_sections.color_id) >= 7 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 10 THEN 1.15 WHEN COUNT(dbo.dir_order_sections.color_id) >= 11 THEN 1.3 ELSE 0 END AS section_rate, CASE WHEN COUNT(dbo.dir_order_sections.color_id) 
                          = 0 THEN 0.03 WHEN COUNT(dbo.dir_order_sections.color_id) >= 1 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 2 THEN 0.04 WHEN COUNT(dbo.dir_order_sections.color_id) >= 3 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 7 THEN 0.05 WHEN COUNT(dbo.dir_order_sections.color_id) >= 8 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 10 THEN 0.07 WHEN COUNT(dbo.dir_order_sections.color_id) >= 11 THEN 0.07 ELSE 0 END AS role_rate, CASE WHEN COUNT(dbo.dir_order_sections.color_id) 
                          = 0 THEN 0.03 WHEN COUNT(dbo.dir_order_sections.color_id) >= 1 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 2 THEN 0.04 WHEN COUNT(dbo.dir_order_sections.color_id) >= 3 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 7 THEN 0.05 WHEN COUNT(dbo.dir_order_sections.color_id) >= 8 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 10 THEN 0.07 WHEN COUNT(dbo.dir_order_sections.color_id) >= 11 THEN 0.07 ELSE 0 END AS role_shift_rate_base, ISNULL(SUM(dbo.colors.role_shift_rate_add), 
                          0) + CASE WHEN COUNT(dbo.dir_order_sections.color_id) = 0 THEN 0.03 WHEN COUNT(dbo.dir_order_sections.color_id) >= 1 AND 
                          COUNT(dbo.dir_order_sections.color_id) <= 2 THEN 0.04 WHEN COUNT(dbo.dir_order_sections.color_id) >= 3 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 7 THEN 0.05 WHEN COUNT(dbo.dir_order_sections.color_id) >= 8 AND COUNT(dbo.dir_order_sections.color_id) 
                          <= 9 THEN 0.06 WHEN COUNT(dbo.dir_order_sections.color_id) >= 10 THEN 0.07 ELSE 0 END AS role_shift_rate, dbo.orders.order_n
    FROM         dbo.orders LEFT OUTER JOIN
                          dbo.dir_order_sections ON dbo.dir_order_sections.order_n = dbo.orders.order_n AND dbo.dir_order_sections.color_id <> 0 AND 
                          dbo.dir_order_sections.color_id IS NOT NULL LEFT OUTER JOIN
                          dbo.colors ON dbo.dir_order_sections.color_id = dbo.colors.color_id
    GROUP BY dbo.orders.order_n

    someone, 15 Июля 2012

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

    +117

    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
    public class Foo { 
     public Foo() {
      System.out.println("constructing foo: " + this);
      throw new RuntimeException();
     }
     public void doEvil() {
      System.out.println("Evil!Evil!Evil");
     }
    }
    
    public class MyFoo extends Foo {
     public static Foo x;
     @Override
     protected void finalize() throws Throwable {
      x = this;
     } 
    }
    
    try {
     Foo x = new MyFoo();
    } catch(Exception e) {
     System.out.println(""+e);
    }
    System.gc();
    System.runFinalization();
    System.out.println("MyFoo instance: " + MyFoo.x);
    MyFoo.x.doEvil();

    Вот так бесстрашные хакеры получают доступ к методу экземпляра объекта, конструктор которого выбрасывает исключение, а потом жалуются, что, мол, Java - решето.

    А теперь вопрос на засыпку: как сделать то же самое, не используя finalize и gc?

    someone, 12 Июля 2012

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

    +119

    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
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    /**
     * Imbues the given {@link Font} with support for fallback fonts,
     * needed to display CJK characters in fonts that do not support them.
     * 
     * This is an ugly mess that depends on internal Sun APIs. Use sparingly!
     *
     * @param font the font
     * @return the composite font UI resource
     */
    public static FontUIResource getCompositeFontUIResource(final Font font) {
    	try {
    		Class<?> klass;
    		
    		try {
    			// Java 7
    			klass = Class.forName("sun.font.FontUtilities");
    		} catch (final ClassNotFoundException e) {
    			// Java 6
    			klass = Class.forName("sun.font.FontManager");
    		}
    		
    		// Invoke static method that wraps the font
    		val method = klass.getMethod("getCompositeFontUIResource", Font.class);
    		return (FontUIResource) method.invoke(null, font);
    	} catch (final ClassNotFoundException e) {
    		// Long block of catches that cannot happen on a Sun JRE
    		throw new AssertionError(e);
    	} catch (final IllegalAccessException e) {
    		throw new AssertionError(e);
    	} catch (final IllegalArgumentException e) {
    		throw new AssertionError(e);
    	} catch (final InvocationTargetException e) {
    		throw new AssertionError(e);
    	} catch (final NoSuchMethodException e) {
    		throw new AssertionError(e);
    	} catch (final SecurityException e) {
    		throw new AssertionError(e);
    	}
    }

    someone, 10 Июля 2012

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

    +118

    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
    31. 31
    private String compileOwnerName() {
    		return Joiner.on(' ').skipNulls().
    		String firstName = ownerFirstName.getValue();
    		String lastName = ownerLastName.getValue();
    		
    		final StringBuilder buffer = new StringBuilder();
    		boolean first = true;
    		
    		if (firstName != null) {
    			firstName = firstName.trim();
    			
    			if (!"".equals(firstName)) {
    				buffer.append(firstName);
    				first = false;
    			}
    		}
    
    		if (lastName != null) {
    			lastName = lastName.trim();
    			
    			if (!"".equals(lastName)) {
    				if (!first) {
    					buffer.append(" ");
    				}
    				
    				buffer.append(lastName);
    			}
    		}
    		
    		return buffer.toString();
    	}

    В итоге заменено однострочником на Perl:

    return Joiner.on(' ').skipNulls().join(Strings.emptyToNull(ownerFirstName.getValue().trim()),
    ownerLastName.getValue().trim()));

    someone, 05 Июля 2012

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

    −138

    1. 1
    2. 2
    3. 3
    4. 4
    -CREATE TABLE CN_RedoReason (<...>, UNIQUE U_CN_RRSN_NAME1 (name)) ENGINE = innodb;
    -CREATE TABLE CN_RejectReason (<...>, UNIQUE U_CN_RRSN_NAME (name)) ENGINE = innodb;
    +CREATE TABLE CN_RedoReason (<...>, UNIQUE U_CN_RRSN_NAME (name)) ENGINE = innodb;
    +CREATE TABLE CN_RejectReason (<...>, UNIQUE U_CN_RRSN_NAME1 (name)) ENGINE = innodb;

    Дифф коммита.

    Автогенерация схемы такая автогенерация. Зависит от того, какая таблица первой под руку попадётся.

    someone, 05 Июля 2012

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

    +121

    1. 1
    2. 2
    3. 3
    @SuppressWarnings("deprecation")
    // Stupid GWT doesn't have Calendar, so we have to use a deprecated method. :(
    final int year = new Date().getYear() + 1900;

    someone, 02 Июля 2012

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

    +124

    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
    31. 31
    32. 32
    33. 33
    34. 34
    BufferedReader file = null;
        boolean moreData = true;
        //set the parameters
        this.textureDir = textureDir;
    
        //open a file
        try{
          file = new BufferedReader(
              new InputStreamReader(
              (new FileInputStream(filename))), 50000);
        } catch (Exception e) {System.err.println("kan model niet laden"); moreData = false;}
    
        //read shapes until no more data
        while(moreData)
        {
          Shape3D shape = readShape(file);
          if(shape != null)
          {
            tg.addChild(shape);
    
          }
          else
          {
            moreData = false;
          }
        }
    
        try{
          file.close();
          file=null;
        } catch (IOException e)
        {
          System.err.println("file " + filename + " could not be closed!");
        }

    Интересный способ обработки ошибок ввода-вывода.

    Естественно, при неудачном открытии файла вываливается по NullPointerException.

    someone, 20 Июня 2012

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

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // Handle Ctrl-1 ... Ctrl-9 keypresses
    if (!event.isSpecialKey() && event.isControlKey()) {
    	final int code = event.getKeyCode();
    	
    	if (code >= '1' && code <= '9') {
    		// Technically, the keyCode is not the ASCII code and should not
    		// be treated as such. Stupid JavaScript events. However, it
    		// *just so happens* that for number keys these codes match their
    		// ASCII codes. Luckily for us.

    someone, 08 Июня 2012

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

    +111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // WARNING!
    // This has to be optional=true so that OpenJPA uses
    // LEFT JOIN instead of INNER JOIN. Otherwise, MySQL tries
    // using a temporary table (horrible for performance) and dies.
    @ManyToOne(optional = true)
    @NotNull
    private Font font;

    someone, 31 Мая 2012

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