From bcb867b84fc528bfdeea1ee950ef9ba1bcfe04e0 Mon Sep 17 00:00:00 2001 From: Pavel Drasil Date: Fri, 11 Aug 2023 22:52:55 +0200 Subject: [PATCH] Resolved deprecations --- BNCompiler/src/main/antlr/org/bn/compiler/parser/ASN1.g | 6 +++--- .../main/java/org/bn/coders/ASN1PreparedElementData.java | 2 +- JavaLibrary/src/main/java/org/bn/coders/Decoder.java | 6 +++--- JavaLibrary/src/main/java/org/bn/coders/Encoder.java | 2 +- JavaLibrary/src/main/java/org/bn/coders/ber/BERDecoder.java | 2 +- .../src/main/java/org/bn/coders/per/PERAlignedDecoder.java | 2 +- .../src/main/java/org/bn/coders/per/PERAlignedEncoder.java | 2 +- .../src/test/java/org/bn/coders/CoderTestUtilities.java | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/BNCompiler/src/main/antlr/org/bn/compiler/parser/ASN1.g b/BNCompiler/src/main/antlr/org/bn/compiler/parser/ASN1.g index ef6eb37e..76be35e7 100644 --- a/BNCompiler/src/main/antlr/org/bn/compiler/parser/ASN1.g +++ b/BNCompiler/src/main/antlr/org/bn/compiler/parser/ASN1.g @@ -256,10 +256,10 @@ AsnOidComponent oidcmp; AsnDefinedValue defval; } obj_id_component returns [AsnOidComponent oidcmp ] {oidcmp = new AsnOidComponent(); AsnDefinedValue defval; String s,n =""; } - : ((num:NUMBER {s=num.getText();oidcmp.num = new Integer(s); oidcmp.numberForm=true;}) + : ((num:NUMBER {s=num.getText();oidcmp.num = Integer.valueOf(s); oidcmp.numberForm=true;}) | (LOWER (L_PAREN NUMBER R_PAREN)?)=>((lid:LOWER {oidcmp.name = lid.getText();oidcmp.nameForm=true;}) ( L_PAREN - (num1:NUMBER {n=num1.getText(); oidcmp.num = new Integer(n);oidcmp.nameAndNumberForm=true;}) + (num1:NUMBER {n=num1.getText(); oidcmp.num = Integer.valueOf(n);oidcmp.nameAndNumberForm=true;}) R_PAREN ) ? ) | (defined_value)=>(defval = defined_value {oidcmp.isDefinedValue=true;oidcmp.defval=defval;})) ; @@ -731,7 +731,7 @@ clazz returns [String s] class_NUMBER returns [AsnClassNumber cnum] {cnum = new AsnClassNumber() ; String s; } - : ((num:NUMBER {s=num.getText(); cnum.num = new Integer(s);}) + : ((num:NUMBER {s=num.getText(); cnum.num = Integer.valueOf(s);}) | (lid:LOWER {s=lid.getText(); cnum.name = s ;}) ) ; diff --git a/JavaLibrary/src/main/java/org/bn/coders/ASN1PreparedElementData.java b/JavaLibrary/src/main/java/org/bn/coders/ASN1PreparedElementData.java index 0e8c97f8..e59bfbfe 100644 --- a/JavaLibrary/src/main/java/org/bn/coders/ASN1PreparedElementData.java +++ b/JavaLibrary/src/main/java/org/bn/coders/ASN1PreparedElementData.java @@ -277,6 +277,6 @@ private void setupMemberFlag(Class cls) { @Override public Object newInstance() throws Exception { - return newInstanceConstructor == null ? newInstanceClass.newInstance() : newInstanceConstructor.newInstance(); + return newInstanceConstructor == null ? newInstanceClass.getDeclaredConstructor().newInstance() : newInstanceConstructor.newInstance(); } } diff --git a/JavaLibrary/src/main/java/org/bn/coders/Decoder.java b/JavaLibrary/src/main/java/org/bn/coders/Decoder.java index 13504157..5b1bcac7 100644 --- a/JavaLibrary/src/main/java/org/bn/coders/Decoder.java +++ b/JavaLibrary/src/main/java/org/bn/coders/Decoder.java @@ -50,7 +50,7 @@ public T decode(InputStream stream, Class objectClass) throws Exception { ElementInfo elemInfo = new ElementInfo(); elemInfo.setAnnotatedClass(objectClass); - T objectInstance = objectClass.newInstance(); + T objectInstance = objectClass.getDeclaredConstructor().newInstance(); if (objectInstance instanceof IASN1PreparedElement) { elemInfo.setPreparedInstance(objectInstance); return (T) decodePreparedElement(decodeTag(stream), objectClass, elemInfo, stream).getValue(); @@ -179,7 +179,7 @@ protected Object createInstanceForElement(Class objectClass, ElementInfo element } } if (result == null) { - result = objectClass.newInstance(); + result = objectClass.getDeclaredConstructor().newInstance(); /*Constructor decl = objectClass.getDeclaredConstructor(); decl.setAccessible(true); result = decl.newInstance();*/ @@ -338,7 +338,7 @@ public DecodedObject decodeEnum(DecodedObject decodedTag, Class< DecodedObject itemValue = decodeEnumItem(decodedTag, field.getType(), enumClass, elementInfo, stream); if (itemValue != null) { - T result = objectClass.newInstance(); + T result = objectClass.getDeclaredConstructor().newInstance(); Field param = null; for (Field enumItem : enumClass.getDeclaredFields()) { diff --git a/JavaLibrary/src/main/java/org/bn/coders/Encoder.java b/JavaLibrary/src/main/java/org/bn/coders/Encoder.java index b7ab036e..173f2fb4 100644 --- a/JavaLibrary/src/main/java/org/bn/coders/Encoder.java +++ b/JavaLibrary/src/main/java/org/bn/coders/Encoder.java @@ -195,7 +195,7 @@ protected int encodeSequenceField(Object object, int fieldIdx, Field field, Outp return 0; } else if ( CoderUtils.isDefaultField(field, info) ) { // skip the field if the current value equals to the default value (this is optional for BER, but mandatory for DER) - Object newSequenceInstance = elementInfo.hasPreparedInfo() ? elementInfo.getPreparedInfo().newInstance() : object.getClass().newInstance(); + Object newSequenceInstance = elementInfo.hasPreparedInfo() ? elementInfo.getPreparedInfo().newInstance() : object.getClass().getDeclaredConstructor().newInstance(); CoderUtils.initDefaultValues(newSequenceInstance); Object defaultFieldValue = invokeGetterMethodForField(field, newSequenceInstance, info); return CoderUtils.equals(defaultFieldValue, invokeObjResult) ? 0 : encodeClassType(invokeObjResult, stream, info); diff --git a/JavaLibrary/src/main/java/org/bn/coders/ber/BERDecoder.java b/JavaLibrary/src/main/java/org/bn/coders/ber/BERDecoder.java index 713bc2da..15790afb 100644 --- a/JavaLibrary/src/main/java/org/bn/coders/ber/BERDecoder.java +++ b/JavaLibrary/src/main/java/org/bn/coders/ber/BERDecoder.java @@ -264,7 +264,7 @@ public DecodedObject decodeNull(DecodedObject decodedTag, Class< return null; } stream.read(); // ignore null length - return new DecodedObject<>(objectClass.newInstance(), 1); + return new DecodedObject<>(objectClass.getDeclaredConstructor().newInstance(), 1); } @Override diff --git a/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedDecoder.java b/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedDecoder.java index a740c186..ad6f1874 100644 --- a/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedDecoder.java +++ b/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedDecoder.java @@ -413,7 +413,7 @@ public DecodedObject decodeAny(DecodedObject decodedTag, Class public DecodedObject decodeNull(DecodedObject decodedTag, Class objectClass, ElementInfo elementInfo, InputStream stream) throws Exception { - return new DecodedObject<>(objectClass.newInstance()); + return new DecodedObject<>(objectClass.getDeclaredConstructor().newInstance()); } @Override diff --git a/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedEncoder.java b/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedEncoder.java index 7bcf2e29..41cd1f19 100644 --- a/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedEncoder.java +++ b/JavaLibrary/src/main/java/org/bn/coders/per/PERAlignedEncoder.java @@ -369,7 +369,7 @@ protected int encodeSequencePreamble(Object object, Field[] fields, ElementInfo if (invokeObjResult==null) { ((BitArrayOutputStream) stream).writeBit(false); } else if (CoderUtils.isDefaultField(field, info)) { - Object newSequenceInstance = elementInfo.hasPreparedInfo() ? elementInfo.getPreparedInfo().newInstance() : object.getClass().newInstance(); + Object newSequenceInstance = elementInfo.hasPreparedInfo() ? elementInfo.getPreparedInfo().newInstance() : object.getClass().getDeclaredConstructor().newInstance(); CoderUtils.initDefaultValues(newSequenceInstance); Object defaultFieldValue = invokeGetterMethodForField(field, newSequenceInstance, info); ((BitArrayOutputStream) stream).writeBit(!CoderUtils.equals(defaultFieldValue, invokeObjResult)); diff --git a/JavaLibrary/src/test/java/org/bn/coders/CoderTestUtilities.java b/JavaLibrary/src/test/java/org/bn/coders/CoderTestUtilities.java index 8e6d1ebb..d13dd63e 100644 --- a/JavaLibrary/src/test/java/org/bn/coders/CoderTestUtilities.java +++ b/JavaLibrary/src/test/java/org/bn/coders/CoderTestUtilities.java @@ -209,7 +209,7 @@ public TestRecursiveDefinetion createTestRecursiveDefinition() { public TestI createUnboundedTestInteger() { TestI value = new TestI(); - value.setValue(new Long(0xFAFBFC)); + value.setValue(Long.valueOf(0xFAFBFC)); return value; }