Uploaded image for project: 'Byteman'
  1. Byteman
  2. BYTEMAN-450

Casting throwing error with 4.0.23

XMLWordPrintable

    • Not associated with a product

      I have this in my code base:

       

          private static DeltaValue getUpcomingThresholdCAPDeltaValue
          (BigDecimal aInCurrentValue,CounterInstanceClass aInCounterInstanceClass,
                  ProrateInfo aInProrateFactor,REWrapper aInREWrapper)
          {
              List<ThresholdProfileGroupInstance> lThresholdCapInstances =
                      EntityCounterUtility.getCounterThresholdCapList
                              (aInCounterInstanceClass);
              TPAResources.debug(logger, "process for getting list of Caps" ,
                      " and Thresholds from counter completed.");
              CounterCapThresholdReservation lCounterCapThresholdReservation=new CounterCapThresholdReservation();
              lCounterCapThresholdReservation.setRatingEngineRequest(aInREWrapper.getRatingEngineRequest());
              List<DeltaValue> lOutCapThresholdDeltas = lCounterCapThresholdReservation.getMinTPGDelta
                      (lThresholdCapInstances, aInCurrentValue,
                              RatingCallActions.COMMIT, aInProrateFactor,
                              aInCounterInstanceClass.getUsageLimit(),
                              aInCounterInstanceClass.getKindOfUnit(),
                              aInCounterInstanceClass.getMaxOverageCount());
              DeltaValue lOutCapThresholdDelta = lOutCapThresholdDeltas.get(0);
              setHardStopDeltaIfRejectAction(lOutCapThresholdDeltas, lOutCapThresholdDelta);
              checkAndSetSPInRecurrentThresh(aInREWrapper, lOutCapThresholdDeltas);
              TPAResources.debug(logger, "minDelta value of upcoming " ,
                              "threshold and counter current value:",
                      lOutCapThresholdDelta);
              return lOutCapThresholdDelta;
          } 

       

      Rule used:

       

      # File callType.btm line 6
      RULE callTypeCheck.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue
      CLASS com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility
      METHOD getUpcomingThresholdCAPDeltaValue
      COMPILE
      AFTER WRITE $lOutCapThresholdDeltas
      BIND
      TPA_LOGGER:Logger = com.alcatel.tpapps.common.common.TPAResources.getLogger();
      lIsReserveUpdate : boolean = $aInREWrapper != null && $aInREWrapper.getContextManagement() != null && $aInREWrapper.getContextManagement().isReserveUpdate();
      lIsInitialRequest : boolean = $aInREWrapper != null && $aInREWrapper.getRatingEngineRequest() != null  && $aInREWrapper.getRatingEngineRequest().getCall() != null
      && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext() != null && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType() != null &&
      $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType().equals(RequestType.INITIAL_REQUEST);IF (lIsReserveUpdate || lIsInitialRequest)
      DO
      $lThresholdCapInstances = com.nokia.tpapps.ratingcore.engine.impl.EntityCounterUtility.getCounterThresholdCapList($aInCounterInstanceClass);
      $lOutCapThresholdDeltas = $lCounterCapThresholdReservation.getMinTPGDelta(
      $lThresholdCapInstances, $aInCurrentValue,
      RatingCallActions.RESERVE, $aInProrateFactor,
      $aInCounterInstanceClass.getUsageLimit(),
      $aInCounterInstanceClass.getKindOfUnit(),
      $aInCounterInstanceClass.getMaxOverageCount());
      com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.setHardStopDeltaIfRejectAction($lOutCapThresholdDeltas, $lOutCapThresholdDeltas.get(0));
      TPA_LOGGER.info("[BMAN] ThresholdExecutionUtility evalute value" + $lThresholdCapInstances);
      ENDRULE
      Transformed in:
      loader: com.nokia.tpapps.rating-core [204]
      trigger method: com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue(java.math.BigDecimal,com.nokia.tpapps.servicemodel.model.CounterInstanceClass,com.nokia.tpapps.servicemodel.model.ProrateInfo,com.nokia.tpapps.ratingcore.common.impl.REWrapper) com.nokia.tpapps.servicemodel.model.DeltaValue
       

      Now at runtime:

      # File callType.btm line 6
      RULE callTypeCheck.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue
      CLASS com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility
      METHOD getUpcomingThresholdCAPDeltaValue
      COMPILE
      AFTER WRITE $lOutCapThresholdDeltas
      BIND
      TPA_LOGGER:Logger = com.alcatel.tpapps.common.common.TPAResources.getLogger();
      lIsReserveUpdate : boolean = $aInREWrapper != null && $aInREWrapper.getContextManagement() != null && $aInREWrapper.getContextManagement().isReserveUpdate();
      lIsInitialRequest : boolean = $aInREWrapper != null && $aInREWrapper.getRatingEngineRequest() != null  && $aInREWrapper.getRatingEngineRequest().getCall() != null
      && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext() != null && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType() != null &&
      $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType().equals(RequestType.INITIAL_REQUEST);IF (lIsReserveUpdate || lIsInitialRequest)
      DO
      $lThresholdCapInstances = com.nokia.tpapps.ratingcore.engine.impl.EntityCounterUtility.getCounterThresholdCapList($aInCounterInstanceClass);
      $lOutCapThresholdDeltas = $lCounterCapThresholdReservation.getMinTPGDelta(
      $lThresholdCapInstances, $aInCurrentValue,
      RatingCallActions.RESERVE, $aInProrateFactor,
      $aInCounterInstanceClass.getUsageLimit(),
      $aInCounterInstanceClass.getKindOfUnit(),
      $aInCounterInstanceClass.getMaxOverageCount());
      com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.setHardStopDeltaIfRejectAction($lOutCapThresholdDeltas, $lOutCapThresholdDeltas.get(0));
      TPA_LOGGER.info("[BMAN] ThresholdExecutionUtility evalute value" + $lThresholdCapInstances);
      ENDRULE
      Transformed in:
      loader: com.nokia.tpapps.rating-core [204]
      trigger method: com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue(java.math.BigDecimal,com.nokia.tpapps.servicemodel.model.CounterInstanceClass,com.nokia.tpapps.servicemodel.model.ProrateInfo,com.nokia.tpapps.ratingcore.common.impl.REWrapper) com.nokia.tpapps.servicemodel.model.DeltaValue
      failed to compile
      Rule.ensureTypeCheckedCompiled : error type checking rule callTypeCheck.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue
      org.jboss.byteman.rule.exception.TypeException: MethodExpression.typeCheck : invalid expected type com.nokia.tpapps.servicemodel.model.DeltaValue file callType.btm line 22
      at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:202)
      at org.jboss.byteman.rule.expression.MethodExpression.findMethod(MethodExpression.java:297)
      at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:187)
      at org.jboss.byteman.rule.Action.typeCheck(Action.java:106)
      at org.jboss.byteman.rule.Rule.typeCheck(Rule.java:601)
      at org.jboss.byteman.rule.Rule.ensureTypeCheckedCompiled(Rule.java:529)
      at org.jboss.byteman.rule.Rule.execute(Rule.java:808)
       

       

      Then .. I created a HELPER and loaded that helper in the jvm arg:

       

      package com.nokia.byteman;import org.jboss.byteman.rule.Rule;
      import org.jboss.byteman.rule.helper.Helper;/**
       * Custom Byteman helper providing utility methods for use in Byteman rules.
       *
       * <p>Example usage in a Byteman rule:
       * <pre>
       * RULE Example
       * CLASS my.pkg.Target
       * METHOD doWork
       * HELPER com.nokia.byteman.BytemanHelper
       * AT ENTRY
       * IF TRUE
       * DO
       *   MyType t = cast($0, MyType.class);
       * ENDRULE
       * </pre>
       */
      public class BytemanHelper extends Helper {    public BytemanHelper(Rule rule) {
              super(rule);
          }    /**
           * Casts an object to the specified type.
           *
           * @param <T>   the target type
           * @param value the object to cast (may be null)
           * @param type  the target class
           * @return the cast object, or null if value is null
           * @throws ClassCastException if value is not an instance of type
           */
          public <T> T cast(Object value, Class<T> type) {
              if (value == null) {
                  return null;
              }
              if (type == null) {
                  throw new ClassCastException("BytemanHelper.cast target type is null");
              }
              if (!type.isInstance(value)) {
                  throw new ClassCastException(
                          "BytemanHelper.cast cannot cast " + value.getClass().getName()
                                  + " to " + type.getName());
              }
              return type.cast(value);
          }
      } 
      [root@asifa-me-231 auto]# lsof -p 26820 |grep byteman
      lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/42/gvfs
            Output information may be incomplete.
      lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /home/asifa/.gvfs
            Output information may be incomplete.
      java    26820 tpaadmin  mem       REG              253,0    858547    405822 /opt/SPS_26_3_R1/tmp/byteman.jar
      java    26820 tpaadmin  mem       REG              253,0      1521    405824 /opt/SPS_26_3_R1/tmp/byteman-helper.jar
      java    26820 tpaadmin  109r      REG              253,0     16364    400357 /opt/SPS_26_3_R1/osgi/custo/common-byteman-2.1.0-alpha.108-6369.jar
      java    26820 tpaadmin  313r      REG              253,0     15536    400345 /opt/SPS_26_3_R1/osgi/custo/byteman-submit-4.0.23.jar
      java    26820 tpaadmin  822r      REG              253,0    858547    405822 /opt/SPS_26_3_R1/tmp/byteman.jar
      java    26820 tpaadmin  824r      REG              253,0    858547    405822 /opt/SPS_26_3_R1/tmp/byteman.jar
      java    26820 tpaadmin  826r      REG              253,0      1521    405824 /opt/SPS_26_3_R1/tmp/byteman-helper.jar
       

      Rule changed with use of HELPER and loaded:

      # File callType.btm line 7
      RULE callTypeCheck.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue
      CLASS com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility
      METHOD getUpcomingThresholdCAPDeltaValue
      HELPER com.nokia.byteman.BytemanHelper
      COMPILE
      AFTER WRITE $lOutCapThresholdDeltas
      BIND
      TPA_LOGGER:Logger = com.alcatel.tpapps.common.common.TPAResources.getLogger();
      lIsReserveUpdate : boolean = $aInREWrapper != null && $aInREWrapper.getContextManagement() != null && $aInREWrapper.getContextManagement().isReserveUpdate();
      lIsInitialRequest : boolean = $aInREWrapper != null && $aInREWrapper.getRatingEngineRequest() != null  && $aInREWrapper.getRatingEngineRequest().getCall() != null
      && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext() != null && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType() != null &&
      $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType().equals(RequestType.INITIAL_REQUEST);IF (lIsReserveUpdate || lIsInitialRequest)
      DO
      $lThresholdCapInstances = com.nokia.tpapps.ratingcore.engine.impl.EntityCounterUtility.getCounterThresholdCapList($aInCounterInstanceClass);
      $lOutCapThresholdDeltas = $lCounterCapThresholdReservation.getMinTPGDelta(
      $lThresholdCapInstances, $aInCurrentValue,
      RatingCallActions.RESERVE, $aInProrateFactor,
      $aInCounterInstanceClass.getUsageLimit(),
      $aInCounterInstanceClass.getKindOfUnit(),
      $aInCounterInstanceClass.getMaxOverageCount());
      com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.setHardStopDeltaIfRejectAction($lOutCapThresholdDeltas, cast($lOutCapThresholdDeltas.get(0),com.nokia.tpapps.servicemodel.model.DeltaValue.class));
      TPA_LOGGER.info("[BMAN] ThresholdExecutionUtility evalute value" + $lThresholdCapInstances);
      ENDRULE
      Transformed in:
      loader: com.nokia.tpapps.rating-core [204]
      trigger method: com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue(java.math.BigDecimal,com.nokia.tpapps.servicemodel.model.CounterInstanceClass,com.nokia.tpapps.servicemodel.model.ProrateInfo,com.nokia.tpapps.ratingcore.common.impl.REWrapper) com.nokia.tpapps.servicemodel.model.DeltaValue 

      At runtime:

      # File callType.btm line 7
      RULE callTypeCheck.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue
      CLASS com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility
      METHOD getUpcomingThresholdCAPDeltaValue
      HELPER com.nokia.byteman.BytemanHelper
      COMPILE
      AFTER WRITE $lOutCapThresholdDeltas
      BIND
      TPA_LOGGER:Logger = com.alcatel.tpapps.common.common.TPAResources.getLogger();
      lIsReserveUpdate : boolean = $aInREWrapper != null && $aInREWrapper.getContextManagement() != null && $aInREWrapper.getContextManagement().isReserveUpdate();
      lIsInitialRequest : boolean = $aInREWrapper != null && $aInREWrapper.getRatingEngineRequest() != null  && $aInREWrapper.getRatingEngineRequest().getCall() != null
      && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext() != null && $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType() != null &&
      $aInREWrapper.getRatingEngineRequest().getCall().getCommonCallContext().getRequestType().equals(RequestType.INITIAL_REQUEST);IF (lIsReserveUpdate || lIsInitialRequest)
      DO
      $lThresholdCapInstances = com.nokia.tpapps.ratingcore.engine.impl.EntityCounterUtility.getCounterThresholdCapList($aInCounterInstanceClass);
      $lOutCapThresholdDeltas = $lCounterCapThresholdReservation.getMinTPGDelta(
      $lThresholdCapInstances, $aInCurrentValue,
      RatingCallActions.RESERVE, $aInProrateFactor,
      $aInCounterInstanceClass.getUsageLimit(),
      $aInCounterInstanceClass.getKindOfUnit(),
      $aInCounterInstanceClass.getMaxOverageCount());
      com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.setHardStopDeltaIfRejectAction($lOutCapThresholdDeltas, cast($lOutCapThresholdDeltas.get(0),com.nokia.tpapps.servicemodel.model.DeltaValue.class));
      TPA_LOGGER.info("[BMAN] ThresholdExecutionUtility evalute value" + $lThresholdCapInstances);
      ENDRULE
      Transformed in:
      loader: com.nokia.tpapps.rating-core [204]
      trigger method: com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue(java.math.BigDecimal,com.nokia.tpapps.servicemodel.model.CounterInstanceClass,com.nokia.tpapps.servicemodel.model.ProrateInfo,com.nokia.tpapps.ratingcore.common.impl.REWrapper) com.nokia.tpapps.servicemodel.model.DeltaValue
      failed to compile
      Rule.ensureTypeCheckedCompiled : error type checking rule callTypeCheck.ThresholdExecutionUtility.getUpcomingThresholdCAPDeltaValue
      org.jboss.byteman.rule.exception.TypeException: MethodExpression.typeCheck : invalid expected type com.nokia.tpapps.servicemodel.model.DeltaValue file callType.btm line 23
      at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:202)
      at org.jboss.byteman.rule.expression.MethodExpression.findMethod(MethodExpression.java:297)
      at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:187)
      at org.jboss.byteman.rule.Action.typeCheck(Action.java:106)
      at org.jboss.byteman.rule.Rule.typeCheck(Rule.java:601)
      at org.jboss.byteman.rule.Rule.ensureTypeCheckedCompiled(Rule.java:529)
       

       

      Why the HELPER approach is not working ?

      Tried explicit casting as

      com.nokia.tpapps.ratingcore.engine.impl.ThresholdExecutionUtility.setHardStopDeltaIfRejectAction($lOutCapThresholdDeltas, (com.nokia.tpapps.servicemodel.model.DeltaValue)$lOutCapThresholdDeltas.get(0));

      It fails to submit at first place itself.

              rhn-engineering-adinn Andrew Dinn
              narendrasingh2 Narendra SINGH2
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: