From 3641f1626df6b9b1c11dd3f16b01a01495f4662d Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 15 Aug 2020 16:30:09 +0200 Subject: [PATCH] Collection.toArray() call style There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation. Signed-off-by: Lars Grefer --- .../aspectj/ajde/core/internal/AjdeCoreBuildManager.java | 2 +- .../main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java | 2 +- .../java/org/aspectj/apache/bcel/classfile/JavaClass.java | 2 +- .../java/org/aspectj/apache/bcel/generic/ClassGen.java | 2 +- .../org/aspectj/internal/tools/build/SampleGatherer.java | 4 ++-- .../aspectj/weaver/loadtime/ConcreteAspectCodeGen.java | 3 +-- .../main/java/org/aspectj/ajdt/ajc/BuildArgParser.java | 2 +- .../org/aspectj/ajdt/internal/compiler/ast/AstUtil.java | 2 +- .../ajdt/internal/compiler/lookup/EclipseScope.java | 4 ++-- .../ajdt/internal/compiler/lookup/EclipseSourceType.java | 6 +++--- .../internal/compiler/lookup/InterTypeMemberFinder.java | 4 ++-- .../internal/compiler/batch/BasicCommandTestCase.java | 7 ++++--- .../ajdt/internal/compiler/batch/CommandTestCase.java | 2 +- .../src/main/java/org/aspectj/weaver/MemberImpl.java | 2 +- .../src/main/java/org/aspectj/weaver/ResolvedType.java | 2 +- .../aspectj/weaver/patterns/AnnotationPatternList.java | 2 +- .../org/aspectj/weaver/patterns/BasicTokenSource.java | 2 +- .../main/java/org/aspectj/weaver/patterns/IfPointcut.java | 2 +- .../java/org/aspectj/weaver/patterns/TypePatternList.java | 2 +- .../java/org/aspectj/weaver/patterns/WildTypePattern.java | 8 ++++---- .../test/java/org/aspectj/weaver/CommonWorldTests.java | 2 +- .../src/test/java/org/aspectj/weaver/TestUtils.java | 2 +- .../org/aspectj/tools/ant/taskdefs/compilers/Ajc.java | 2 +- .../java/org/aspectj/testing/util/options/Values.java | 2 +- util/src/main/java/org/aspectj/util/FileUtil.java | 2 +- .../main/java/org/aspectj/weaver/bcel/AtAjAttributes.java | 2 +- .../main/java/org/aspectj/weaver/bcel/BcelObjectType.java | 2 +- .../main/java/org/aspectj/weaver/bcel/LazyMethodGen.java | 2 +- .../tools/cache/AbstractIndexedFileCacheBacking.java | 2 +- 29 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java b/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java index 49948db46..a8b82ce7f 100644 --- a/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java +++ b/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java @@ -256,7 +256,7 @@ public class AjdeCoreBuildManager { } args[p++] = "-xmlConfigured"; } else { - args = l.toArray(new String[l.size()]); + args = l.toArray(new String[0]); } } diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java index 41d13e37e..42d029e06 100644 --- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -897,7 +897,7 @@ class HtmlDecorator { }; file.walk(walker); - return (IProgramElement[]) nodes.toArray(new IProgramElement[nodes.size()]); + return (IProgramElement[]) nodes.toArray(new IProgramElement[0]); } /** diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java index bb42a07ee..014ad558d 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java @@ -741,7 +741,7 @@ public class JavaClass extends Modifiers implements Cloneable, Node { for (clazz = clazz.getSuperClass(); clazz != null; clazz = clazz.getSuperClass()) { vec.add(clazz); } - return vec.toArray(new JavaClass[vec.size()]); + return vec.toArray(new JavaClass[0]); } /** diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java index 371013997..03c7c716b 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java @@ -196,7 +196,7 @@ public class ClassGen extends Modifiers implements Cloneable { ConstantPool cp = this.cpool.getFinalConstantPool(); return new JavaClass(classnameIndex, superclassnameIndex, filename, major, minor, modifiers, cp, interfaces, fields, - methods, attributes.toArray(new Attribute[attributes.size()]));// OPTIMIZE avoid toArray()? + methods, attributes.toArray(new Attribute[0]));// OPTIMIZE avoid toArray()? } public void addInterface(String name) { diff --git a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java index ce7f2ce27..86782563f 100644 --- a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java +++ b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java @@ -221,7 +221,7 @@ public class SampleGatherer { source, startLine, endLine, - flags.toArray(new String[flags.size()])); + flags.toArray(new String[0])); sink.addSample(sample); // back to seeking start @@ -978,7 +978,7 @@ class SampleUtil { } next = anchorName.substring(start); result.add(next); - return result.toArray(new String[result.size()]); + return result.toArray(new String[0]); } /** * Replace literals with literals in source string diff --git a/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java b/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java index fcc89ac75..f89d30c87 100644 --- a/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java +++ b/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java @@ -910,8 +910,7 @@ public class ConcreteAspectCodeGen { } // Time to construct the method itself: - LazyMethodGen advice = new LazyMethodGen(Modifier.PUBLIC, returnType, adviceName, paramTypes.toArray(new Type[paramTypes - .size()]), EMPTY_STRINGS, cg); + LazyMethodGen advice = new LazyMethodGen(Modifier.PUBLIC, returnType, adviceName, paramTypes.toArray(new Type[0]), EMPTY_STRINGS, cg); InstructionList adviceBody = advice.getBody(); diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/BuildArgParser.java index 07332990f..a68698697 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -177,7 +177,7 @@ public class BuildArgParser extends Main { // javaArgList.add("-bootclasspath"); // javaArgList.add(parser.bootclasspath == null ? System.getProperty("user.dir") : parser.bootclasspath); javaArgList.addAll(parser.getUnparsedArgs()); - super.configure(javaArgList.toArray(new String[javaArgList.size()])); + super.configure(javaArgList.toArray(new String[0])); if (parser.getModuleInfoArgument() != null) { IModule moduleDesc = super.getModuleDesc(parser.getModuleInfoArgument()); diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AstUtil.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AstUtil.java index 369e84c51..6dc405653 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AstUtil.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AstUtil.java @@ -112,7 +112,7 @@ public class AstUtil { } public static void setStatements(MethodDeclaration ret, List statements) { - ret.statements = (Statement[]) statements.toArray(new Statement[statements.size()]); + ret.statements = (Statement[]) statements.toArray(new Statement[0]); } public static SingleNameReference makeLocalVariableReference(LocalVariableBinding binding) { diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseScope.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseScope.java index 06191629f..74805b9c6 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseScope.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseScope.java @@ -197,9 +197,9 @@ public class EclipseScope implements IScope { importedNamesList.add(world.fromBinding(topType).getName()); } - importedNames = importedNamesList.toArray(new String[importedNamesList.size()]); + importedNames = importedNamesList.toArray(new String[0]); - importedPrefixes = importedPrefixesList.toArray(new String[importedPrefixesList.size()]); + importedPrefixes = importedPrefixesList.toArray(new String[0]); } private void addClassAndParentsToPrefixes(ReferenceBinding binding, List importedPrefixesList) { diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java index 1941ad630..4731a86ed 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java @@ -349,9 +349,9 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate { declaredFields.add(factory.makeResolvedMember(f)); } - this.declaredPointcuts = declaredPointcuts.toArray(new ResolvedPointcutDefinition[declaredPointcuts.size()]); - this.declaredMethods = declaredMethods.toArray(new ResolvedMember[declaredMethods.size()]); - this.declaredFields = declaredFields.toArray(new ResolvedMember[declaredFields.size()]); + this.declaredPointcuts = declaredPointcuts.toArray(new ResolvedPointcutDefinition[0]); + this.declaredMethods = declaredMethods.toArray(new ResolvedMember[0]); + this.declaredFields = declaredFields.toArray(new ResolvedMember[0]); } private final static char[] valuesCharArray = "values".toCharArray(); diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java index 80ffe4222..1953265c8 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java @@ -270,7 +270,7 @@ public class InterTypeMemberFinder implements IMemberFinder { if (ret.isEmpty()) { return Binding.NO_METHODS; } - return ret.toArray(new MethodBinding[ret.size()]); + return ret.toArray(new MethodBinding[0]); } private void addPublicITDSFrom(SourceTypeBinding anInterface, List accumulator) { @@ -328,7 +328,7 @@ public class InterTypeMemberFinder implements IMemberFinder { // System.err.println("got methods: " + ret + " on " + sourceTypeBinding); - return ret.toArray(new MethodBinding[ret.size()]); + return ret.toArray(new MethodBinding[0]); } @Override diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java index 99ea9b1d9..48a255e91 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java @@ -116,13 +116,14 @@ public class BasicCommandTestCase extends CommandTestCase { args.add(getSandboxName()); args.add("-classpath"); - args.add(getRuntimeClasspath() + File.pathSeparator + "../lib/junit/junit.jar;../testing-client/bin;not_found_anywhere.jar"); + args.add(getRuntimeClasspath() + File.pathSeparator + + "../lib/junit/junit.jar;../testing-client/bin;not_found_anywhere.jar"); args.add(Constants.TESTDATA_PATH + "/src1/ThisAndModifiers.java"); ICommand command = new AjdtCommand(); MessageHandler myHandler = new MessageHandler(); //myHandler.setInterceptor(org.aspectj.tools.ajc.Main.MessagePrinter.TERSE); - /*boolean result = */command.runCommand((String[])args.toArray(new String[args.size()]), myHandler); + /*boolean result = */command.runCommand((String[])args.toArray(new String[0]), myHandler); //System.err.println("messages: " + Arrays.asList(myHandler.getMessages(IMessage.INFO, true))); // DON'T yet have a way of testing that we actually got a particular info message @@ -142,7 +143,7 @@ public class BasicCommandTestCase extends CommandTestCase { ICommand command = new AjdtCommand(); MessageHandler myHandler = new MessageHandler(); myHandler.setInterceptor(org.aspectj.tools.ajc.Main.MessagePrinter.TERSE); - /*boolean result = */command.runCommand((String[])args.toArray(new String[args.size()]), myHandler); + /*boolean result = */command.runCommand((String[])args.toArray(new String[0]), myHandler); assertEquals("error for org.aspectj.lang.JoinPoint not found", 1, myHandler.getErrors().length); } diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java index 6e163efc0..9e8deb0a1 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java @@ -112,7 +112,7 @@ public abstract class CommandTestCase extends TestCase { ICommand command = new AjdtCommand(); MessageHandler myHandler = new MessageHandler(); myHandler.setInterceptor(org.aspectj.tools.ajc.Main.MessagePrinter.TERSE); - boolean result = command.runCommand((String[]) args.toArray(new String[args.size()]), myHandler); + boolean result = command.runCommand((String[]) args.toArray(new String[0]), myHandler); System.out.println("result: " + result); // System.out.println("errors: " + Arrays.asList(myHandler.getErrors())); // System.out.println("warnings: " + Arrays.asList(myHandler.getWarnings())); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/MemberImpl.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/MemberImpl.java index 86caa48c5..d7bd742b8 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/MemberImpl.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/MemberImpl.java @@ -211,7 +211,7 @@ public class MemberImpl implements Member { l.add(UnresolvedType.forSignature(sig.substring(start, i))); } } - UnresolvedType[] paramTypes = l.toArray(new UnresolvedType[l.size()]); + UnresolvedType[] paramTypes = l.toArray(new UnresolvedType[0]); UnresolvedType returnType = UnresolvedType.forSignature(sig.substring(i + 1, sig.length())); return new Object[] { returnType, paramTypes }; } else { diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java index 3d88279af..293a7766c 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java @@ -1082,7 +1082,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl l.add(m); } } - return l.toArray(new ResolvedMember[l.size()]); + return l.toArray(new ResolvedMember[0]); } public abstract ISourceContext getSourceContext(); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnnotationPatternList.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnnotationPatternList.java index 2cc737347..f906a397e 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnnotationPatternList.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnnotationPatternList.java @@ -50,7 +50,7 @@ public class AnnotationPatternList extends PatternNode { } public AnnotationPatternList(List l) { - this((AnnotationTypePattern[]) l.toArray(new AnnotationTypePattern[l.size()])); + this((AnnotationTypePattern[]) l.toArray(new AnnotationTypePattern[0])); } protected AnnotationTypePattern[] getAnnotationPatterns() { diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/BasicTokenSource.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/BasicTokenSource.java index ef537d807..15713e76d 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/BasicTokenSource.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/BasicTokenSource.java @@ -160,7 +160,7 @@ public class BasicTokenSource implements ITokenSource { //System.out.println(tokens); - return new BasicTokenSource((IToken[])tokens.toArray(new IToken[tokens.size()]), context); + return new BasicTokenSource((IToken[])tokens.toArray(new IToken[0]), context); } private static String makeString(char ch) { diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java index 8c2cb36b9..4e614824a 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java @@ -308,7 +308,7 @@ public class IfPointcut extends Pointcut { } } - ret = Test.makeAnd(ret, Test.makeCall(testMethod, (Expr[]) args.toArray(new Expr[args.size()]))); + ret = Test.makeAnd(ret, Test.makeCall(testMethod, (Expr[]) args.toArray(new Expr[0]))); // Remember... ifLastMatchedShadowId = shadow.shadowId; diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java index 2b17520a2..fdbc40d12 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java @@ -59,7 +59,7 @@ public class TypePatternList extends PatternNode { } public TypePatternList(List l) { - this((TypePattern[]) l.toArray(new TypePattern[l.size()])); + this((TypePattern[]) l.toArray(new TypePattern[0])); } public int size() { diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java index c5f44ae0f..b8c4ac31b 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java @@ -110,7 +110,7 @@ public class WildTypePattern extends TypePattern { } public WildTypePattern(List names, boolean includeSubtypes, int dim) { - this((NamePattern[]) names.toArray(new NamePattern[names.size()]), includeSubtypes, dim, false, TypePatternList.EMPTY); + this((NamePattern[]) names.toArray(new NamePattern[0]), includeSubtypes, dim, false, TypePatternList.EMPTY); } @@ -127,7 +127,7 @@ public class WildTypePattern extends TypePattern { public WildTypePattern(List names, boolean includeSubtypes, int dim, int endPos, boolean isVarArg, TypePatternList typeParams, TypePattern upperBound, TypePattern[] additionalInterfaceBounds, TypePattern lowerBound) { - this((NamePattern[]) names.toArray(new NamePattern[names.size()]), includeSubtypes, dim, isVarArg, typeParams); + this((NamePattern[]) names.toArray(new NamePattern[0]), includeSubtypes, dim, isVarArg, typeParams); this.end = endPos; this.upperBound = upperBound; this.lowerBound = lowerBound; @@ -135,7 +135,7 @@ public class WildTypePattern extends TypePattern { } public WildTypePattern(List names, boolean includeSubtypes, int dim, int endPos, boolean isVarArg, TypePatternList typeParams) { - this((NamePattern[]) names.toArray(new NamePattern[names.size()]), includeSubtypes, dim, isVarArg, typeParams); + this((NamePattern[]) names.toArray(new NamePattern[0]), includeSubtypes, dim, isVarArg, typeParams); this.end = endPos; } @@ -1169,7 +1169,7 @@ public class WildTypePattern extends TypePattern { } } } - return ret.toArray(new String[ret.size()]); + return ret.toArray(new String[0]); } // public void postRead(ResolvedType enclosingType) { diff --git a/org.aspectj.matcher/src/test/java/org/aspectj/weaver/CommonWorldTests.java b/org.aspectj.matcher/src/test/java/org/aspectj/weaver/CommonWorldTests.java index 9389fff8b..613437346 100644 --- a/org.aspectj.matcher/src/test/java/org/aspectj/weaver/CommonWorldTests.java +++ b/org.aspectj.matcher/src/test/java/org/aspectj/weaver/CommonWorldTests.java @@ -189,7 +189,7 @@ public abstract class CommonWorldTests extends TestCase { protected void mungersTest(ResolvedType ty, ShadowMunger[] x) { List l = ty.getDeclaredShadowMungers(); - ShadowMunger[] array = (ShadowMunger[]) l.toArray(new ShadowMunger[l.size()]); + ShadowMunger[] array = (ShadowMunger[]) l.toArray(new ShadowMunger[0]); TestUtil.assertSetEquals(ty + " mungers:", x, array); } diff --git a/org.aspectj.matcher/src/test/java/org/aspectj/weaver/TestUtils.java b/org.aspectj.matcher/src/test/java/org/aspectj/weaver/TestUtils.java index 9f7daa756..69bc674ef 100644 --- a/org.aspectj.matcher/src/test/java/org/aspectj/weaver/TestUtils.java +++ b/org.aspectj.matcher/src/test/java/org/aspectj/weaver/TestUtils.java @@ -298,7 +298,7 @@ public class TestUtils { l.add(str.substring(start, i).trim()); start = i + 1; } - return (String[]) l.toArray(new String[l.size()]); + return (String[]) l.toArray(new String[0]); } } diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java index 022dcae22..25128bb61 100644 --- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java +++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java @@ -138,7 +138,7 @@ public class Ajc extends DefaultCompilerAdapter { argsList.add(args[i]); } } - return (String[])argsList.toArray(new String[argsList.size()]); + return (String[])argsList.toArray(new String[0]); } /** diff --git a/testing/src/test/java/org/aspectj/testing/util/options/Values.java b/testing/src/test/java/org/aspectj/testing/util/options/Values.java index af81692b7..de35c8c67 100644 --- a/testing/src/test/java/org/aspectj/testing/util/options/Values.java +++ b/testing/src/test/java/org/aspectj/testing/util/options/Values.java @@ -402,7 +402,7 @@ public class Values { } } } - return (String[]) list.toArray(new String[list.size()]); + return (String[]) list.toArray(new String[0]); } private final Option.Value[] values; diff --git a/util/src/main/java/org/aspectj/util/FileUtil.java b/util/src/main/java/org/aspectj/util/FileUtil.java index 976c3ccbc..a586b69f6 100644 --- a/util/src/main/java/org/aspectj/util/FileUtil.java +++ b/util/src/main/java/org/aspectj/util/FileUtil.java @@ -710,7 +710,7 @@ public class FileUtil { if ((null != srcDir) && srcDir.canRead()) { listFiles(srcDir, result, fileFilter); } - return result.toArray(new File[result.size()]); + return result.toArray(new File[0]); } /** diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java index 96222fba2..5f2032704 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -1905,7 +1905,7 @@ public class AtAjAttributes { ignores.add(formalBinding.getName()); } } - pointcut.m_ignoreUnboundBindingForNames = ignores.toArray(new String[ignores.size()]); + pointcut.m_ignoreUnboundBindingForNames = ignores.toArray(new String[0]); } /** diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java index 47984dfdf..922769dc0 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java @@ -399,7 +399,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { if (pointcuts.size() == 0) { this.pointcuts = ResolvedPointcutDefinition.NO_POINTCUTS; } else { - this.pointcuts = pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]); + this.pointcuts = pointcuts.toArray(new ResolvedPointcutDefinition[0]); } resolveAnnotationDeclares(l); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java index 3ab0c5daf..7e2541e6c 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -336,7 +336,7 @@ public final class LazyMethodGen implements Traceable { public AnnotationAJ[] getAnnotations() { initialize(); if (memberView == null && newAnnotations!=null && newAnnotations.size()!=0) { - return newAnnotations.toArray(new AnnotationAJ[newAnnotations.size()]); + return newAnnotations.toArray(new AnnotationAJ[0]); } return null; } diff --git a/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java b/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java index cb05b10e0..32dba3d90 100644 --- a/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java +++ b/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java @@ -71,7 +71,7 @@ public abstract class AbstractIndexedFileCacheBacking extends AbstractFileCacheB if (matches.isEmpty()) { return EMPTY_KEYS; } else { - return matches.toArray(new String[matches.size()]); + return matches.toArray(new String[0]); } } -- 2.39.5