BUG-50 : removed sonar warnings. 46/2346/1
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 4 Nov 2013 08:23:03 +0000 (09:23 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Mon, 4 Nov 2013 08:23:03 +0000 (09:23 +0100)
Change-Id: I2877d6c7611e49bdf596a2f93c3e85d5c3a84752
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractEROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractObjectWithTlvsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractRROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROExplicitExclusionRouteSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROLabelSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKeySubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROLabelSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java

index 8f5ed1bdd8253ab389fba4bb72b9df727273d65d..9f7303a7fb1577dc65a0199fa599b911b84856c9 100644 (file)
@@ -25,7 +25,7 @@ import com.google.common.primitives.UnsignedBytes;
 
 public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
 
-       private static final Logger logger = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
+       private static final Logger LOG = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
 
        private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
        private static final int SUB_LENGTH_F_LENGTH = 1;
@@ -46,7 +46,7 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
                        throw new IllegalArgumentException("Byte array is mandatory.");
                }
 
-               boolean loose_flag = false;
+               boolean loose = false;
                int type;
                byte[] soContentsBytes;
                int length;
@@ -56,7 +56,7 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
 
                while (offset < bytes.length) {
 
-                       loose_flag = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+                       loose = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
                        length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
 
                        type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
@@ -69,9 +69,9 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
                        soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
                        System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
 
-                       logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
-                       final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, loose_flag);
-                       logger.debug("Subobject was parsed. {}", sub);
+                       LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
+                       final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, loose);
+                       LOG.debug("Subobject was parsed. {}", sub);
 
                        subs.add(sub);
 
index 92634743d2aaa1538be90a4cbc18ff266708c78e..ef4610bccdd361c90fd8aab73f758480c768df1c 100644 (file)
@@ -19,9 +19,9 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
 
-public abstract class AbstractObjectWithTlvsParser<BUILDER> implements ObjectParser, ObjectSerializer {
+public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, ObjectSerializer {
 
-       private static final Logger logger = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class);
+       private static final Logger LOG = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class);
 
        private static final int TLV_TYPE_F_LENGTH = 2;
        private static final int TLV_LENGTH_F_LENGTH = 2;
@@ -35,7 +35,7 @@ public abstract class AbstractObjectWithTlvsParser<BUILDER> implements ObjectPar
                this.tlvReg = Preconditions.checkNotNull(tlvReg);
        }
 
-       protected final void parseTlvs(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException {
+       protected final void parseTlvs(final T builder, final byte[] bytes) throws PCEPDeserializerException {
                if (bytes == null) {
                        throw new IllegalArgumentException("Byte array is mandatory.");
                }
@@ -60,9 +60,9 @@ public abstract class AbstractObjectWithTlvsParser<BUILDER> implements ObjectPar
 
                        final byte[] tlvBytes = ByteArray.subByte(bytes, byteOffset, length);
 
-                       logger.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes));
+                       LOG.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes));
                        final Tlv tlv = this.tlvReg.getTlvParser(type).parseTlv(tlvBytes);
-                       logger.trace("Tlv was parsed. {}", tlv);
+                       LOG.trace("Tlv was parsed. {}", tlv);
 
                        addTlv(builder, tlv);
 
@@ -84,12 +84,14 @@ public abstract class AbstractObjectWithTlvsParser<BUILDER> implements ObjectPar
 
                int byteOffset = 0;
                System.arraycopy(typeBytes, 0, bytes, byteOffset, TLV_TYPE_F_LENGTH);
-               System.arraycopy(lengthBytes, 0, bytes, byteOffset += TLV_TYPE_F_LENGTH, TLV_LENGTH_F_LENGTH);
-               System.arraycopy(valueBytes, 0, bytes, byteOffset += TLV_LENGTH_F_LENGTH, valueBytes.length);
+               byteOffset += TLV_TYPE_F_LENGTH;
+               System.arraycopy(lengthBytes, 0, bytes, byteOffset, TLV_LENGTH_F_LENGTH);
+               byteOffset += TLV_LENGTH_F_LENGTH;
+               System.arraycopy(valueBytes, 0, bytes, byteOffset, valueBytes.length);
                return bytes;
        }
 
-       public abstract void addTlv(final BUILDER builder, final Tlv tlv);
+       public abstract void addTlv(final T builder, final Tlv tlv);
 
        protected static int getPadding(final int length, final int padding) {
                return (padding - (length % padding)) % padding;
index 788d7b11ad2f63ee44355e135789c42d389cda46..8aa514860529b0d5db4c8d7417891287b584f36e 100644 (file)
@@ -24,7 +24,7 @@ import com.google.common.collect.Lists;
 
 public abstract class AbstractRROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
 
-       private static final Logger logger = LoggerFactory.getLogger(AbstractRROWithSubobjectsParser.class);
+       private static final Logger LOG = LoggerFactory.getLogger(AbstractRROWithSubobjectsParser.class);
 
        private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
        private static final int SUB_LENGTH_F_LENGTH = 1;
@@ -67,9 +67,9 @@ public abstract class AbstractRROWithSubobjectsParser implements ObjectParser, O
                        soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
                        System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
 
-                       logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
+                       LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
                        final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes);
-                       logger.debug("Subobject was parsed. {}", sub);
+                       LOG.debug("Subobject was parsed. {}", sub);
 
                        subs.add(sub);
 
index 881d5fc19d08a81835dd37b88c93d99bf798770b..535ebb7d517e6bf5eece8f0666628058ad9d1052 100644 (file)
@@ -55,7 +55,7 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<LspaBuild
        private static final int SET_PRIO_F_OFFSET = INC_ALL_F_OFFSET + INC_ALL_F_LENGTH;
        private static final int HOLD_PRIO_F_OFFSET = SET_PRIO_F_OFFSET + SET_PRIO_F_LENGTH;
        private static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
-       private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B
+       private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1;
 
        public PCEPLspaObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
index 30b3b832cf7828766a920845fb32c096ddc1d6b7..54151f2c904969b81d8a13c44428e09f35875d64 100644 (file)
@@ -22,13 +22,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder;
 
 import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
 
 public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
 
        public static final int TYPE = 33;
 
-       private static final int RESERVED = 2;
-
        private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
        private static final int SUB_LENGTH_F_LENGTH = 1;
        private static final int SUB_HEADER_LENGTH = SUB_TYPE_FLAG_F_LENGTH + SUB_LENGTH_F_LENGTH;
@@ -119,7 +118,7 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
                return subs;
        }
 
-       private final byte[] serializeSubobject(
+       private byte[] serializeSubobject(
                        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> subobjects) {
 
                final List<byte[]> result = Lists.newArrayList();
@@ -130,15 +129,13 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
 
                        final XROSubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject.getSubobjectType());
 
-                       System.out.println(serializer);
-
                        final byte[] valueBytes = serializer.serializeSubobject(subobject);
 
                        final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
 
                        final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
                                        : 0));
-                       final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
+                       final byte lengthBytes = UnsignedBytes.checkedCast(valueBytes.length);
 
                        bytes[0] = typeBytes;
                        bytes[1] = lengthBytes;
index 8c0975925f4b31416e766e17b5dac900a60b1620..b266e06404bd9f0914ba2baeffc28de27a29484f 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
 
 import com.google.common.base.Preconditions;
+import com.google.common.primitives.UnsignedBytes;
 
 public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
 
@@ -58,12 +59,12 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
                }
                final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
 
-               final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
+               final short cType = (short) UnsignedBytes.toInt(buffer[C_TYPE_F_OFFSET]);
 
-               final LabelParser parser = this.registry.getLabelParser(c_type);
+               final LabelParser parser = this.registry.getLabelParser(cType);
 
                if (parser == null) {
-                       throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
+                       throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
                }
                final LabelBuilder builder = new LabelBuilder();
                builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
@@ -92,7 +93,7 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
                final BitSet reserved = new BitSet();
                reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
                System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
-               retBytes[C_TYPE_F_OFFSET] = (byte) serializer.getType();
+               retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(serializer.getType());
                return retBytes;
        }
 
index 3ae15631180863e711c3dda89cab12f6f2f253cf..3203bcc2dc3999cafdf7cfd964fd8982cbd333e7 100644 (file)
@@ -14,14 +14,13 @@ import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
 
 /**
- * Parser for {@link PathKeySubobject}
+ * Parser for {@link PathKey}
  */
 public class EROPathKeySubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
 
index c5e9e40327afd4ded93fb390ab278d59a2e6283b..21f6903026372f20721e88bfa3c7c994dea2f4fe 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.LabelBuilder;
 
 import com.google.common.base.Preconditions;
+import com.google.common.primitives.UnsignedBytes;
 
 public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
 
@@ -59,12 +60,12 @@ public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobject
                }
                final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
 
-               final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
+               final short cType = (short) UnsignedBytes.toInt(buffer[C_TYPE_F_OFFSET]);
 
-               final LabelParser parser = this.registry.getLabelParser(c_type);
+               final LabelParser parser = this.registry.getLabelParser(cType);
 
                if (parser == null) {
-                       throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
+                       throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
                }
                final LabelBuilder builder = new LabelBuilder();
                builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
@@ -89,7 +90,7 @@ public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobject
                reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
                reserved.set(G_FLAG_OFFSET, label.isGlobal());
                System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
-               retBytes[C_TYPE_F_OFFSET] = (byte) parser.getType();
+               retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(parser.getType());
                return retBytes;
        }
 
index 1f72e30eef1bac457347e231bd3ba9fb2777499c..5a45b711fcf4092183ba1b438f84e68f2b1b3fac 100644 (file)
@@ -13,7 +13,6 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.LspIdentifiers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.LspIdentifiersBuilder;
@@ -28,7 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
 
 /**
- * Parser for {@link LspIdentifiersTlv}
+ * Parser for {@link LspIdentifiers}
  */
 public class LSPIdentifierTlvParser implements TlvParser, TlvSerializer {