Bêtisier 2008

Article publié par Xebia France le 31 décembre 2008.

Catégorie(s) : Divers

 

4 commentaires »

L’époque s’y prête : pour finir l’année en beauté, et exploiter une formule qui fait les choux gras de TF1, voici une sélection de perles que nous avons rencontrées en 2008, sur des projets ou sur la toile.

Elle vient compléter notre sélection de l’année dernière.

N’hésitez pas à poster en commentaire vos propres rencontres du troisième type … A vous de jouer !

Liberté

Un chef de projet en conversation téléphonique avec un juriste inquiet :

« Oui, oui, on utilise des logiciels libres, … oui c’est libre d’achat, par contre pour faire des modifications c’est payant. »

Le soucis avec vos applications, ce sont les middlewares.

D’une équipe d’exploitation spécialisée J2EE : « Ah non, vous ne pouvez pas utiliser Hibernate, ça va nous faire un middleware de plus à installer et à surveiller, déjà qu’on ne s’en sort pas avec Weblogic et Oracle… »

Les exceptions sont vos amis

[...]
try{
  lstParamType_[0] = String.class;
  /*
   * if (logger.isDebug()) { logger.debug(" --- paramType_[0] = String"); }
   */
  dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_, lstParamType_);
  lstParamMethodeSet_[0] = valeurAttributDuXml_;
} catch (NoSuchMethodException e){
  try{
    lstParamType_[0] = Integer.class;
    /*
     * if (logger.isDebug()) { logger.debug(" --- paramType_[0] = Integer"); }
     */
    dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_, lstParamType_);
    lstParamMethodeSet_[0] = Integer.getInteger((String) valeurAttributDuXml_);
  } catch (NoSuchMethodException e1){
    try{
      lstParamType_[0] = Date.class;
      /*
       * if (logger.isDebug()) { logger.debug(" --- paramType_[0] = Date"); }
       */
      dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_, lstParamType_);
      try{
        lstParamMethodeSet_[0] = BoDate.stringToDate((String) valeurAttributDuXml_,
          BoDateConstante.FORMAT_DATE_STANDARD);
      } catch (BaseException e2){
        lstParamMethodeSet_[0] = BoDate.stringToDate((String) valeurAttributDuXml_,
          DD_MMYYYY);
      }
    } catch (NoSuchMethodException e2){
      try{
        lstParamType_[0] = Boolean.class;
        /*
         * if (logger.isDebug()) { logger.debug(" --- paramType_[0] = Boolean"); }
         */
        dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_, lstParamType_);
        lstParamMethodeSet_[0] = new Boolean((String) valeurAttributDuXml_);
      } catch (NoSuchMethodException e3){
        try{
          lstParamType_[0] = Double.class;
          /*
           * if (logger.isDebug()) { logger.debug(" --- paramType_[0] = Double"); }
           */
          dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_, lstParamType_);
          lstParamMethodeSet_[0] = new Double((String) valeurAttributDuXml_);
        } catch (NoSuchMethodException e4){
          try{
            lstParamType_[0] = Float.class;
            /*
             * if (logger.isDebug()) { logger.debug(" --- paramType_[0] = Float"); }
             */
            dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_, lstParamType_);
            lstParamMethodeSet_[0] = new Float((String) valeurAttributDuXml_);
          } catch (NoSuchMethodException e5){
            try{
              lstParamType_[0] = int.class;
              /*
               * if (logger.isDebug()) { logger.debug(" --- paramType_[0] = int"); }
               */
              dtoMethodeSet_ = dtoClass_
                .getMethod(nomDtoMethodeSet_, lstParamType_);
              lstParamMethodeSet_[0] = new Integer((String) valeurAttributDuXml_);
            } catch (NoSuchMethodException e6){
              try{
                lstParamType_[0] = boolean.class;
                /*
                 <strong> if (logger.isDebug()) { logger.debug(" --- paramType_[0] =
                 </strong> boolean"); }
                 */
                dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_,
                  lstParamType_);
                lstParamMethodeSet_[0] = new Boolean((String) valeurAttributDuXml_);
              } catch (NoSuchMethodException e7){
                try{
                  lstParamType_[0] = float.class;
                  /*
                   <strong> if (logger.isDebug()) { logger.debug(" --- paramType_[0] =
                   </strong> float"); }
                   */
                  dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_,
                    lstParamType_);
                  lstParamMethodeSet_[0] = new Float((String) valeurAttributDuXml_);
                } catch (NoSuchMethodException e8){
                  try{
                    lstParamType_[0] = double.class;
                    /*
                     <strong> if (logger.isDebug()) { logger.debug(" --- paramType_[0] =
                     </strong> double"); }
                     */
                    dtoMethodeSet_ = dtoClass_.getMethod(nomDtoMethodeSet_,
                      lstParamType_);
                    lstParamMethodeSet_[0] = new Double(
                      (String) valeurAttributDuXml_);
                  } catch (NoSuchMethodException eDernier){
                    throw new TechniqueException(AutomatMapping.class,
                      "Erreur dans AutomatMapping.mappingXmlObject2Dto : aucune méthode "
                        + nomDtoMethodeSet_ + " trouvée sur l'objet "
                        + dtoClass_.getName() + "n" + eDernier.getMessage());
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
[...]

Quelques problèmes de performances sûrement, les logs ont été commentés …

L’art de réinventer la roue

[...]
public boolean equals(Object x, Object y) {
    if (x == y) {
		return true;
	}
    if (x == null || y == null) {
		return false;
	}
    return x.equals(y);
}
[...]

Et une version « optimisée » :

[...]
public boolean equals(Object x, Object y) throws HibernateException {
    return (x == y) || (x != null && x.equals(y));
}
[...]

On n’est jamais trop sûr

[...]
public boolean compareString(String str1, String str2)
{
	if(str1 == str2) {
		return true;
	}
	if(str1 == null || str2 == null) {
		return false;
	}
	if(str1.equals(str2)) {
		return true;
	}
	return false;
}
[...]

4 réponses à “Bêtisier 2008”

  1. [...]
    public boolean compareString(String str1, String str2)
    {
    if(str1 == str2) {
    return true;
    }
    if(str1 == null || str2 == null) {
    return false;
    }
    if(str1.equals(str2)) {
    return true;
    }
    return equals(str1,str2);
    }
    [...]

  2. Nicolas dit :

    Vu dans du code…

    1) Le gars qui pense connaitre java… mais non

    public static final String TRUE_S=String.valueOf(Boolean.TRUE);

    2) Phénomene je mets 3 preservatifs

    try {
    // something


    } catch (Throwable e) {
    logger.error(e,e);
    System.err.println(e);
    e.printStackTrace();
    throw e
    }

  3. Alex dP dit :

    J’en ai une bonne moi aussi. L’action se passe en réunion « base de données » chez un éditeur d’ERP. Le sujet du jour est : gestion de planning des employés. Et là, la première proposition qui tombe par l’un participants est : « Et si on faisait une table avec 365 colonnes? »… un blanc… je me retiens de rire puis je réponds sérieusement : « Et tu fais comment pour les années bisextiles? »… »ah, oui merde! ».

  4. Thibaud dit :

    Entretien téléphonique avec le chef de projet (précision : nous sommes en sous-traitance sur le projet, la personne qui gère l’ensemble du projet n’est pas chez nous, nous n’avons pas de contact avec le client final).

    « Le client souhaite un document de « spécifications fonctionnelles détaillées ». Je vais voir avec lui ce qu’il entend par là. »

    De ce matin…

Laisser un commentaire

 

Page optimized by WP Minify WordPress Plugin