private String getEmailTemplateWithActualValueForAccount (modèle String, compte de compte) jette IllegalArgumentException, IllegalAccessException, InvocationTargetException {exception java
Map<String,String> map = new HashMap<String, String>();
List<String> listTags = new ArrayList<String>();
Map<Method, String> methodList = new HashMap<Method, String>();
int startIndex=0;
int endIndex=0;
for(int i=0; i<template.length(); i++)
{
char ch = template.charAt(i);
if(ch=='$')
startIndex = i+1;
if(ch=='#')
{
endIndex = i+1;
listTags.add(template.substring(startIndex,endIndex));
}
}
Method[] methods = Account.class.getMethods();
for (Method method : methods) {
String methodName = method.getName();
if(method.getName().startsWith("get"))
{
methodList.put(method, methodName.substring(3,methodName.length()).toUpperCase()+"#");
}
}
Set<Method> methodKeySet = methodList.keySet();
for (Method method : methodKeySet) {
for (String string : listTags) {
if(methodList.get(method).equals(string))
{
try{
Object obj = method.invoke(account, null);
if(obj!=null)
map.put(string, obj.toString());
}catch(NullPointerException e){
}
}
}
}
final StringBuilder list = new StringBuilder("\\$(");
for(final String key: map.keySet())
{
list.append(key);
list.append("|");
}
list.append("[^\\s\\S])");
Pattern pattern = Pattern.compile(list.toString());
Matcher matcher = pattern.matcher(template);
final StringBuffer stringBuffer = new StringBuffer();
while(matcher.find()){
final String string = matcher.group(1);
matcher.appendReplacement(stringBuffer, map.get(string));
}
matcher.appendTail(stringBuffer);
return stringBuffer.toString();
}
Je suis une exception à la ligne de code « Object obj = method.invoke (compte, null) " Le code fonctionne parfaitement, mais comme ce code est dans le planificateur, il crée un journal toutes les 20 secondes sur le serveur jboss.
Vous obtiendrez une meilleure réponse si vous ajoutez un contexte à votre question. Avez-vous du code qui le lance? Si oui, postez-le. Êtes-vous inquiet de l'attraper? Si oui, quelles sont les méthodes qui vous inquiètent? – corsiKa
Pourriez-vous fournir votre code qui lève cette exception? – Longball27
... donc le code ne fonctionne PAS parfaitement, n'est-ce pas? Juste parce qu'un code compile, ne le fait pas fonctionner exactement comme vous le vouliez. Évidemment, dans ce cas, ce n'est pas le cas, donc ce n'est pas, en fait, «parfaitement fonctionner». – polygenelubricants