AndreasFagschlunger / O2Xfs

Java API for accessing CEN/XFS API, EMV Level 2 Kernel
47 stars 28 forks source link

Everywhere where you used wrong removing objects from arraylist. #65

Closed VitalyEG closed 6 years ago

VitalyEG commented 6 years ago

Everywhere where you used removing object from arraylist wrong: for (int i = 0; i < XXX.size(); i++) { Object XX = XXX.remove(i); ...

As Example (Wrong): List arrayList = new ArrayList<>(); arrayList.add("A"); arrayList.add("B"); arrayList.add("C"); arrayList.add("D"); arrayList.add("E"); for (int i = 0; i < arrayList.size(); i++) { String str = arrayList.remove(i); System.out.println("str="+ str); } RESULT: str=A str=C str=E

Please use construnction:

Iterator iterator = arrayListX.iterator(); while (iterator.hasNext()) { X xx = iterator.next(); iterator.remove(); }

VitalyEG commented 6 years ago

IssuerToCardScriptProcessing.extractScriptID TaskMAnager.execute XRequestWatchdog.checkRequests

AndreasFagschlunger commented 6 years ago

I agree it would be cleaner, though it shouldn't do any harm (e.g. ConcurrentModificationException). The remove in IssuerToCardScriptProcessing.extractScriptID is valid, since it returns the removed object, the other two however may skip items since the index doesn't get decremented.

VitalyEG commented 6 years ago

I channged code at XRequestWatchdog.checkRequests:

_private void checkRequests() { final String method = "checkRequests()"; final long currentTime = System.currentTimeMillis(); Iterator iterator = requests.iterator(); while (iterator.hasNext()) { Request request = iterator.next(); if (request.getTimeoutTime() > currentTime) { continue; } long activeTime = request.getTimeoutTime() - request.startTime; if (request.cancelled) { if (LOG.isWarnEnabled()) { LOG.warn( method, "Request "

and TaskMAnager.execute at: public void execute(final Task task) { final String method = "execute(Task)"; if (LOG.isDebugEnabled()) { LOG.debug(method, "task=" + task + ",taskPath=" + taskPath); } Iterator iterator = taskPath.iterator(); while (iterator.hasNext()) { Task activeTask = iterator.next(); activeTask.getCommands().removeCommandsChangedListener(this); activeTask.getContent().removeUIContentListener(this); iterator.remove(); } internalExecute(task); }

AndreasFagschlunger commented 6 years ago

Please consider submitting a pull request for feature improvements.