Source:
<code>public void sendRequest(Exchange exchange,final Request request) { if (request.getMID() == Message.NONE) { request.setMID(currendMID.getAndIncrement()%(1<<16)); } KeyMID idByMID = new KeyMID(request.getMID()); KeyToken idByToken; if (request.getToken() == null) { idByToken = createUnusedToken(); request.setToken(idByToken.token); <START> if (exchange.getRequest() != null && exchange.getRequest().getToken() == null) <END> exchange.getRequest().setToken(idByToken.token); } else { idByToken = new KeyToken(request.getToken()); if (!(exchange.getFailedTransmissionCount()>0 || request.getOptions().hasBlock1() || request.getOptions().hasBlock2() || request.getOptions().hasObserve()) && exchangesByToken.get(idByToken) != null) { LOGGER.log(Level.WARNING, "Manual token overrides existing open request: {0}", idByToken); } } if ( request.getOptions().hasObserve() && request.getOptions().getObserve() == 0 && !request.getOptions().hasBlock2()) { observeRequestStore.add(request); request.addMessageObserver(new MessageObserverAdapter() { @Override public void onCancel() { observeRequestStore.remove(request.getToken()); } @Override public void onReject() { observeRequestStore.remove(request.getToken()); } @Override public void onTimeout() { observeRequestStore.remove(request.getToken()); } }); } exchange.setObserver(exchangeObserver); LOGGER.log(Level.FINE, "Tracking open request using {0}, {1}", new Object[]{idByMID, idByToken}); exchangesByMID.put(idByMID, exchange); exchangesByToken.put(idByToken, exchange); }</code><technical_language>explain circumstances this happens</technical_language>

Target:
public void sendRequest(Exchange exchange,final Request request) { if (request.getMID() == Message.NONE) { request.setMID(currendMID.getAndIncrement()%(1<<16)); } KeyMID idByMID = new KeyMID(request.getMID()); KeyToken idByToken; if (request.getToken() == null) { idByToken = createUnusedToken(); request.setToken(idByToken.token); if (exchange.getRequest() != null && exchange.getRequest().getToken() == null) exchange.getRequest().setToken(idByToken.token); } else { idByToken = new KeyToken(request.getToken()); if (!(exchange.getFailedTransmissionCount()>0 || request.getOptions().hasBlock1() || request.getOptions().hasBlock2() || request.getOptions().hasObserve()) && exchangesByToken.get(idByToken) != null) { LOGGER.log(Level.WARNING, "Manual token overrides existing open request: {0}", idByToken); } } if (request.getOptions().hasObserve() && request.getOptions().getObserve() == 0 && (!request.getOptions().hasBlock2() || request.getOptions().getBlock2().getNum() == 0 && !request.getOptions().getBlock2().isM())) { observationStore.add(new Observation(request, null)); request.addMessageObserver(new MessageObserverAdapter() { @Override public void onCancel() { observationStore.remove(request.getToken()); } @Override public void onReject() { observationStore.remove(request.getToken()); } @Override public void onTimeout() { observationStore.remove(request.getToken()); } }); } exchange.setObserver(exchangeObserver); LOGGER.log(Level.FINE, "Tracking open request using {0}, {1}", new Object[]{idByMID, idByToken}); exchangesByMID.put(idByMID, exchange); exchangesByToken.put(idByToken, exchange); }