MyBatis version

3.5.3

Database vendor and version

Test case or example project

public Class resolveAlias(String string) { try { if (string == null) { return null; } // issue #748 String key = string.toLowerCase(Locale.ENGLISH); Class value;

  // java.util.HashMap.get(Object key) has the functionality of containsKey(Object key)
  if (typeAliases.containsKey(key)) {
    value = (Class<T>) typeAliases.get(key);
  } else {
    value = (Class<T>) Resources.classForName(string);
  }


  return value;
} catch (ClassNotFoundException e) {
  throw new TypeException("Could not resolve type alias '" + string + "'.  Cause: " + e, e);
}

}

AND

public void registerAlias(String alias, Class<?> value) { if (alias == null) { throw new TypeException("The parameter alias cannot be null"); } // issue #748 String key = alias.toLowerCase(Locale.ENGLISH);

// java.util.HashMap.put(K key, V value) also has the functionality of containsKey(Object key) & get(Object key)

if (typeAliases.containsKey(key) && typeAliases.get(key) != null && !typeAliases.get(key).equals(value)) {
  throw new TypeException("The alias '" + alias + "' is already mapped to the value '" + typeAliases.get(key).getName() + "'.");
}
typeAliases.put(key, value);

}

Steps to reproduce

Expected result

it may be :

Class<?> o = typeAliases.get(key); if (o != null) { value = (Class) o; } else { value = (Class) Resources.classForName(string); }

AND

// javadoc: the previous value associated with key, or null if there was no mapping for key. // (A null return can also indicate that the map previously associated null with key.)

Class<?> o = typeAliases.put(key, value);
if (o != null) {
    if(o.equals(value)){
        throw new TypeException("The alias '" + alias + "' is already mapped to the value '" + 
            value.getName() + "'.");
    }   
}

Actual result

Comment From: harawata

Hi @galleChristian , Please send a pull request. It's much easier for us to review. https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request And please use the proper syntax for code blocks in a comment. https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown

Comment From: harawata

No reply. Feel free to send us a PR when you have time!