1. Java / Говнокод #3031

    +73.6

    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
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    package psorter;
    
    import java.util.Vector;
    
    public class CArray extends Vector {
        String type="";
    
        /**
         * constructor of /array/
         * @param i set capacity increment
         */
        public CArray(int i) {
    	this.capacityIncrement=i;
        }
    
        /**
         * add object to end of vector with check of type
         * if type same as @ first added - add this object
         * safer than add
         * @param o object to add
         */
        public void append(Object o) {
    	if ( this.type.equals("") )
    	    this.type=o.getClass().toString();
    
    	if ( o.getClass().toString().equals(this.type) ){
    	    this.add(o);
    	} else {
    	    if ( this.type.contains("Float") && o.getClass().toString().contains("Integer") )
    		this.add( Float.valueOf(o.toString()) );
    
    	    if ( this.type.contains("Double") && o.getClass().toString().contains("Integer") )
    		this.add( Double.valueOf(o.toString()) );
    	    if ( this.type.contains("Double") && o.getClass().toString().contains("Float") )
    		this.add( Double.valueOf(o.toString()) );
    
    	    if ( this.type.contains("String") && o.getClass().toString().contains("Char") )
    		this.add( o.toString() );
    	}
        }
    
        public byte compare(int i, int j) throws Exception {
    	if (type.contains("Integer")) {
    	    if ((Integer) (this.get(i)) > (Integer) (this.get(j)))
    		return 1;
    	    if ((Integer) (this.get(i)) < (Integer) (this.get(j)))
    		return -1;
    	    return 0;
    	}
    
    	if (type.contains("Float")) {
    	    if ((Float) (this.get(i)) > (Float) (this.get(j)))
    		return 1;
    	    if ((Float) (this.get(i)) < (Float) (this.get(j)))
    		return -1;
    	    return 0;
    	}
    
    	if (type.contains("Double")) {
    	    if ((Double) (this.get(i)) > (Double) (this.get(j)))
    		return 1;
    	    if ((Double) (this.get(i)) < (Double) (this.get(j)))
    		return -1;
    	    return 0;
    	}
    
    	if (type.contains("Char")) {
    	    if ((Character) (this.get(i)) > (Character) (this.get(j)))
    		return 1;
    	    if ((Character) (this.get(i)) < (Character) (this.get(j)))
    		return -1;
    	    return 0;
    	}
    
    	if (type.contains("String")) {
    	    if ( this.get(i).toString().compareTo(this.get(j).toString())>0 )
    		return 1;
    	    if ( this.get(i).toString().compareTo(this.get(j).toString())<0 )
    		return -1;
    	    return 0;
    	}
    
    	return 0;
        }
    }

    сел писать 3 лабы естественно в последнюю ночь. начал в 11. эта была около 3х. самому потом стыдно было нести такое

    ilardm, 17 Апреля 2010

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

    +74.2

    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
    package efi.base.business.metadata;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    public class MetaModel {
        private String name = null;
        private List attributeNames = new ArrayList();
        private List attributeValues = new ArrayList();
    
        public MetaModel(String name) {
            this.name = name;
        }
    
        public String getName() {
            return name;
        }
    
        public void addAttribute(Attribute attribute) {
            attributeNames.add(attribute.getName());
            attributeValues.add(attribute);
        }
    
        public Attribute getAttribute(String attrubuteName) {
            return (Attribute) attributeValues.get(attributeNames.indexOf(attrubuteName));
        }
    
        public Iterator attributesIterator() {
            return attributeNames.iterator();
        }
    }

    Человек, писавший этот говнокласс, видимо и не подозревал, что в JDK кроме листов есть еще и Map-ы :-)

    Andronix, 14 Апреля 2010

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

    +64.8

    1. 1
    2. 2
    3. 3
    4. 4
    long timer = -System.currentTimeMillis();
    method.invoke(...);
    timer += System.currentTimeMillis();
    log.info("Executed: " + timer + " ms.");

    Obychno ja delaju dve peremennyje start i end:
    long start = System.currentTimeMillis();
    method.invoke(...);
    long end = System.currentTimeMillis();
    log.info("Executed: " + (end-start) + " ms.");

    Inogda ewe ljudi pishut s odnoj peremennoj, no tut vpolne ponjatno, chto v nej hranitsja:
    long t = System.currentTimeMillis();
    method.invoke(...);
    t = System.currentTimeMillis() - t;

    A vot zafigachit' v peremennuju "timer" OTRITSATEL'NOJE znachenije - eto da...

    asolntsev, 13 Апреля 2010

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

    +72.4

    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
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    interface Editor extends Window {
    
        /** Get edited entity  */
        Entity getItem();
    
        /**
         * Set parent datasource to commit into this datasource instead of database.
         * This method must be followed by {@link #setItem(com.contora.package.core.entity.Entity)}
         */
        void setParentDs(Datasource parentDs);
    
        /** Set edited entity. Invoked by the framework on opening the window. */
        void setItem(Entity item);
    
        /** Check validity by invoking validators on all components which support them */
        boolean isValid();
    
        /** Check validity by invoking validators on all components which support them */
        void validate() throws ValidationException;
    
        /** Validate and commit changes */
        boolean commit();
    
        /** Commit changes with optional validating */
        boolean commit(boolean validate);
    
        /**
         * Validate, commit and close if commit was successful.
         * Passes {@link #COMMIT_ACTION_ID} to associated {@link CloseListener}s
         */
        void commitAndClose();
    }
    
    public class PickupRegionLookuper extends AbstractLookup implements Editor{
        public PickupRegionLookuper(IFrame frame) {
            super(frame);
        }
    
        @Override
        protected void init(Map<String, Object> params) {
           //Здесь была какая то логика
        }
    
        @Override
        public Entity getItem() {
            return null;  
        }
    
        @Override
        public void setParentDs(Datasource parentDs) {
        }
    
        @Override
        public void setItem(Entity item) {
        }
    
        @Override
        public boolean isValid() {
            return false;
        }
    
        @Override
        public void validate() throws ValidationException {
        }
    
        @Override
        public boolean commit() {
            return false;
        }
    
        @Override
        public boolean commit(boolean validate) {
            return false;
        }
    
        @Override
        public void commitAndClose() {
        }
    }

    Встретилось в одном java-файле. Класс реализует интерфейс, определенный в том же файле, причем интерфейс package-private (!). При этом ни одного метода оттуда реально не используется. К тому же этот интерфейс человек перенес из другого класса, где тот был как раз public.

    tinhol, 06 Апреля 2010

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

    +69.2

    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
    List<Measure> meaList = q.getResultList();
            try
            {
                if (meaList.size() == 0)
                {
                    throw new Exception("Measure not found: "+_wsPrice.getMeasureIso());
                }
                else
                {
                    p.setMeasure(meaList.get(0));
                }
            }
            finally
            {
                meaList.clear();
            }

    А вот ещё порция паранойи от моего коллеги

    konsoletyper, 06 Апреля 2010

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

    +77.6

    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
    public void run()
        {
            try
            {            
                startExport();
            }
            catch (Throwable _t)
            {
                sendEvent(""+_t.getMessage(), true);
                logger.log(Level.SEVERE, charset, _t);
            }
            finally
            {
                System.gc();
            }
        }

    А ещё этот человек дёргает в одном сервисе gc каждые 4 секунды. Любые попытки ударить по рукам нарываются на отлуп: "так работает же!". Это не студент! Это реальный production код!

    konsoletyper, 06 Апреля 2010

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

    +67.4

    1. 1
    2. 2
    Apache POI
    The apache project has a library which called POI that can read and write the HSSF (Horrible Spread Sheet Format)

    Не говнокод, но официальное название формата доставляет :)

    zlob.jc, 02 Апреля 2010

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

    +69

    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
    if (isRenderVerifyClaimTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.VerifyClaimController");
    		}
    		if (isRenderVerifyAvtoTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.VerifyAvtoController");
    		}
    		if (isRenderUntipicalClaimTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.UntipicalClaimController");
    		}
    		if (isRenderTypeClaimTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.TypeClaimController");
    
    		}

    Профтыкал что можно было делать так:

    if (isRenderCheckClaimTab()) {
    addContrToInit(CheckClaimController.clas s.getName());
    }

    :)

    Lockdog, 01 Апреля 2010

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

    +74.4

    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
    private String getNullString(int kol){
            String nullstr="";
            for(int i=0;i<kol;i++){
                nullstr+="0";
            }
            return nullstr;
        }
    
    public String getNumber(int idd){
            String regid="";
            String idds=(idd+"");
            if(idds.length()<getNumberLenth()){
                regid+=getNullString(getNumberLenth()-idds.length());
                regid+=idds;
            }
            String regnum="";
            regnum+=getNumberPrefix()+regid;
            if(getNumberPeriod()!=NUM_PERIOD_NOPERIOD){
                GregorianCalendar c=new GregorianCalendar();
                switch(getNumberPeriod()){
                    case NUM_PERIOD_MONTH:
                        int m=c.get(Calendar.MONTH)+1;
                        regnum+="-"+m;
                        regnum+=".";
                        regnum+=c.get(Calendar.YEAR);
                        break;
                    case NUM_PERIOD_YEAR:
                        regnum+="-"+c.get(Calendar.YEAR);
                }
            }
            return regnum;
        }

    Ну незнал я про String.format (((..

    maxt, 01 Апреля 2010

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

    +74

    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
    lstCmsObject = OpenCms.getOrgUnitManager().getGroups(obj, "/", true);
                                
                                for (int i = 0; i < lstCmsObject.size(); i++)
                                {
                                	lstUnits.add(new Units(lstCmsObject.get(i).getDisplayName(obj, Locale.US).replaceAll("Users from ","").replaceAll("[a-zA-Z]*","").replaceAll("[(/)]+",""),lstCmsObject.get(i).getOuFqn()));
                                }
                                
                                for (int i = 0; i < lstCmsObject.size(); i++) {
    		                for (int j = 0; j < lstCmsObject.size(); j++) {
    		                    if (lstUnits.get(i).GetName().compareTo(lstUnits.get(j).GetName())<0) {
    		                        Collections.swap(lstUnits, i, j);
    		                    }
    		                }
    		            }

    des-1008d, 30 Марта 2010

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