Here is the weird exception that I get with the appropriate code below:
23:51:39 at java.lang.Thread.run (Unknown source)
23:51:39 at java.util.concurrent.ThreadPoolExecutor $ Worker.run (Unknown source)
23:51:39 at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask (Unknown source)
23:51:39 at com.dk.actions.c.run (Unknown source)
23:51:39 at com.dk.actions.TesterAction.yw (Unknown source)
23:51:39 at com.dk.actions.TesterAction.yX (Unknown source)
23:51:39 at com.dk.agent.tester.b.Bc (Unknown source)
23:51:39 at com.dk.agent.tester.r.run (Unknown source)
23:51:39 at com.dk.agent.tester.ba (Unknown source)
23:51:39 at scal.Scal.onBar (Scal.java:241)
23:51:39 at scal.Supres.evalSupres (Scal.java:2678)
23:51:39 at scal.SR.supp (Scal.java:2187)
23:51:39 at scal.SR.evaluateSRfor (Scal.java:2361)
23:51:39 at scal.SR.isAtSR (Scal.java:2385)
23:51:39 at scal.SR $ Con.access $ 5 (Scal.java:1741)
23:51:39 java.lang.NullPointerException
Oh, before asking, yes, all classes of this application are in one file. Do not ask why. That's how it is. Below are the links with the code for the above stack trace:
ref. scal.Scal.onBar(Scal.java:241): try{ for(Ins instr : supresSourceMap.keySet()) for(Per p : supresSourceMap.get(instr).keySet()) 241: supresSourceMap.get(instr).get(p).evalSupres(currTime); } catch (Exception e){ e.printStackTrace(console.getErr()); } ref. scal.Supres.evalSupres(Scal.java:2678): public void evalSupres(long time) throws Exception{ ... 2678: sup.supp(Con.of(getIns(), getPer(), center, time, conRange, true), null); ... } ref. scal.SR.supp(Scal.java:2187): void supp(Con nHt, Con remove){ ... 2187 evaluateSRfor(nHt); ... } ref. scal.SR.evaluateSRfor(Scal.java:2361): private void evaluateSRfor(Con nHt) { if(!hits.get(nHt.per).isEmpty()){ Con lastHt = getLastHt(nHt.per); if(lastHt != null){ if(lastHt.srSource == null){ if(isNewSR(nHt)){ addNewSR(nHt); } }else{ 2361: if(isAtSR(nHt)){ addConToLastSR(nHt); } } } } } ref. scal.SR.isAtSR(Scal.java:2385): private boolean isAtSR(Con nHt) { ... 2385: double high = nHt.getHighestCon().upperConBound; ... } ref. nHt.getHighestCon() : Con getHighestCon(){ Con highCon = null; boolean contains = false; if(this.srSource != null){ highCon = srSource.getFirst(); for(Con con : srSource){ if(!contains) contains = this.equals(con); if (con.compareTo(highCon) > 0) { highCon = con; } } if(!contains) throw new IllegalStateException("getHighestCon(): " + this.toString() + " does not belong to its srSource list: " + srSource.toString()); } return highCon; } ref. scal.SR$Con.access$5(Scal.java:1741): 1741: private final double upperConBound;
Important notes:
- srSource is a field in the Con class of type LinkedList <>.
- The getHighestCon () method is defined in type Con.
- Type Con is a static inner class in type SR.
- The Con type is immutable, although the srSource list is not final and is then created and populated later from the setter method.
- Each instance of Con contains a reference to itself in the srSource list.
- I applied the Con type with hashCode (), equals (), toString (), Comparable (compareTo (Conf c)). None of them use the srSource field in their calculations.
- The "private final double upperConBound" field is initialized from the Con constructor via the static method:
- this.upperConBound = value + Utils.pValue (ins, conRange);
- The problem does not disappear if I access the field through a method, and not directly.
- However, the problem disappears when I access the upperConBound field from isAtSR () as follows:
- double high = getHighestCon (srSource) .upperConfBound;
- Where:
- sr Report the SR instance field and
- the getHighestCon method (LinkedList <> srSource) is implemented in the SR type in the same way as in the Con type, but access to the parameter instead of a field and throwing an exception.
- Keep in mind that the above solution is not the solution that I am dealing with. I need the getHighestCon () method, which will be implemented and works from the Con type. If you have any questions or need more code samples, please let me know. I appreciate your time spent solving this for me.
source share