Skip to content

Strange NPE issue #500

@victorrodrigueznadq

Description

@victorrodrigueznadq

This is my original clara rule, which was converted from a drools implementation:

(defrule add-all-dlp-firm-symbols
  "Add All DLP Firm Symbols"
  {:salience 1000000}
  [?billingDates <- BillingDates
   ]
  [?dlpFirm <- DlpFirm
   (= ?mpid mpid )
   (= ?symbol symbol )
   ]
  [?symbolBillingLink <- SymbolBillingProgramLink
   (= accountId ?mpid)
   (= symbol ?symbol)
   (nil? terminateDate)
   ]
  =>
  (def volumeAccumulation (VolumeAccumulation.))
  (.setAccountIdentifier volumeAccumulation ?mpid)
  (.setSymbol volumeAccumulation ?symbol)
  (.setNumberOfDays volumeAccumulation (.getNumberOfTradingDates ?billingDates))
  (.setTotalVolume volumeAccumulation (long 0))
  (.setAccumulationLevel volumeAccumulation VolumeAccumulation$AccumulationLevel/ACCOUNT_SYMBOL)
  (.setAccumulationCode volumeAccumulation "nqeAddDlp")
  (.setFirmIdentifier volumeAccumulation (.getFirmId ?symbolBillingLink))
  (insert! (Map/of "$volumeAccumulationWriter" volumeAccumulation))
  )

I was having a memory leak because we didn't have a check to prevent the same VolumeAccumulation records from being created and inserted over an over again each time the rules were fired. So then I added a :not check. I kept betting NPE exceptions complaining about firmIdentifier being null, so I kept adding more and more (some?) checks to ensure, supposedly, that that couldn't never happen, but thusfar, I've been unable to erradicate that NPE exception. Here's what the rule currently looks like (added (insert! volumeAccumulation) to the end of the RHS):

(defrule add-all-dlp-firm-symbols
  "Add All DLP Firm Symbols"
  {:salience 1000000}
  [?billingDates <- BillingDates
   ]
  [?dlpFirm <- DlpFirm
   (= ?mpid mpid )
   (= ?symbol symbol )
   ]
  [?symbolBillingLink <- SymbolBillingProgramLink
   (= accountId ?mpid)
   (= symbol ?symbol)
   (nil? terminateDate)
   (some? firmId)
   ]
  [:not [VolumeAccumulation
         (some? numberOfDays)
         (some? firmIdentifier)
         (some? totalVolume)
         (= accountIdentifier ?mpid)
         (= symbol ?symbol)
         (= numberOfDays (.getNumberOfTradingDates ?billingDates))
         (= totalVolume (long 0))
         (= accumulationLevel VolumeAccumulation$AccumulationLevel/ACCOUNT_SYMBOL)
         (= accumulationCode "nqeAddDlp")
         (= firmIdentifier (.getFirmId ?symbolBillingLink))
         ]]
  =>
  (def volumeAccumulation (VolumeAccumulation.))
  (.setAccountIdentifier volumeAccumulation ?mpid)
  (.setSymbol volumeAccumulation ?symbol)
  (.setNumberOfDays volumeAccumulation (.getNumberOfTradingDates ?billingDates))
  (.setTotalVolume volumeAccumulation (long 0))
  (.setAccumulationLevel volumeAccumulation VolumeAccumulation$AccumulationLevel/ACCOUNT_SYMBOL)
  (.setAccumulationCode volumeAccumulation "nqeAddDlp")
  (.setFirmIdentifier volumeAccumulation (.getFirmId ?symbolBillingLink))
  (insert! volumeAccumulation)
  (insert! (Map/of "$volumeAccumulationWriter" volumeAccumulation))
  )

And, here's the exception:

Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because "this.firmIdentifier" is null
	at com.nasdaq.edm.rms.accumulation.VolumeAccumulation.getFirmIdentifier(VolumeAccumulation.java:252)
	at clojure.core$eval388$AN_136_AE__507.invoke(NO_SOURCE_FILE:42)
	at clara.rules.engine$alpha_node_matches$iter__4093__4097$fn__4098$fn__4099$fn__4100.invoke(engine.cljc:517)
	... 28 common frames omitted

Any ideas what could possibly be going on?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions