Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays.copyOf - no such method error in java 1.5 #1

Closed
ravi-polampelli opened this issue Nov 19, 2012 · 7 comments
Closed

Arrays.copyOf - no such method error in java 1.5 #1

ravi-polampelli opened this issue Nov 19, 2012 · 7 comments
Assignees

Comments

@ravi-polampelli
Copy link
Contributor

Hi Anuj,

I am seeing below exception, I think this is due to Arrays.copyOf method is introduced in 1.6,
As we are saying we support version 1.5 also, I think we need to provide our own method for this function.

java.lang.NoSuchMethodError: java/util/Arrays.copyOf([Ljava/lang/Object;I)[Ljava/lang/Object;
at org.easetech.easytest.loader.CSVDataLoader.writeData(CSVDataLoader.java:182)
at org.easetech.easytest.util.RunAftersWithOutputData.evaluate(RunAftersWithOutputData.java:120)

I saw below code from , http://stackoverflow.com/questions/2789193/java-copyof-method-problem-with-an-array-of-objects

/**

  • Reallocates an array with a new size, and copies the contents

  • of the old array to the new array.

  • @param oldArray the old array, to be reallocated.

  • @param newSize the new array size.

  • @return A new array with the same contents.
    */
    private static Object resizeArray (Object oldArray, int newSize) {
    int oldSize = java.lang.reflect.Array.getLength(oldArray);
    Class elementType = oldArray.getClass().getComponentType();
    Object newArray = java.lang.reflect.Array.newInstance(
    elementType,newSize);
    int preserveLength = Math.min(oldSize,newSize);
    if (preserveLength > 0)
    System.arraycopy (oldArray,0,newArray,0,preserveLength);

    return newArray;
    }

@ghost ghost assigned anujgandharv Nov 19, 2012
@anujgandharv
Copy link
Member

Yes. Arrays.copyOf is a Java 1.6 method.
The above might not work because at one place we need a new array with the size bigger than the original one. Although I am not sure. Will try the above method and let you know.

anujgandharv added a commit that referenced this issue Nov 20, 2012
Updated Java docs to reflect the current state of affairs.
gpcmol added a commit that referenced this issue Nov 21, 2012
ravi-polampelli added a commit that referenced this issue Nov 21, 2012
@ravi-polampelli
Copy link
Contributor Author

Array.copyOf is replaced with System.arraycopy..

Original -
String[] newSplitValues = Arrays.copyOf(splitValues, splitValues.length);

Updated:
String[] newSplitValues = (String[])Array.newInstance(String[].class.getComponentType(), splitValues.length);
System.arraycopy(splitValues, 0, newSplitValues, 0, Math.min(splitValues.length, newSplitValues.length));

@vovkab
Copy link

vovkab commented Jan 30, 2014

The same problem is still exists for android 2.1 (api 8):

java.lang.NoSuchMethodError: java.util.Arrays.copyOf
at com.fasterxml.jackson.core.sym.CharsToNameCanonicalizer.copyArrays(CharsToNameCanonicalizer.java:579)
at com.fasterxml.jackson.core.sym.CharsToNameCanonicalizer.findSymbol(CharsToNameCanonicalizer.java:494)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._parseName(ReaderBasedJsonParser.java:1210)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:612)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2986)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2091)

@anujgandharv
Copy link
Member

HI vovkab,
Could you please elaborate a bit on the scenario when you are getting the error. It will help me solve the issue quicker.

Thanks,
Anuj

@vovkab
Copy link

vovkab commented Feb 11, 2014

Hi anujgandharv,

[Arrays.copyOf](http://developer.android.com/reference/java/util/Arrays.html#copyOf%28U[], int, java.lang.Class<? extends T[]>%29) is available on android only starting from api 9. If you try to run it on api 8 you will get an error.

The solution can be replacing all Arrays.copyOf with System.arraycopy

Thanks!

@anujgandharv
Copy link
Member

Thanks Vladimir.
EasyTest does not have directly any reference to Arrays.copyOf in its source code. Looking at the above stack trace, looks like CharsToNameCanonicalizer class is trying to do Arrays.copyOf. This class is present in jakson-core-lgpl-1.9.11.jar file dependency that EasyTest has.But version 1.9.11 is compatible with Java 1.5 and the code also has System.arraycopy. Are you somehow overriding the jackson JAR version?

@vovkab
Copy link

vovkab commented Feb 11, 2014

Hi Anuj

Looks like I'm on wrong "forum" :)

I use latest jackson:
compile 'com.fasterxml.jackson.core:jackson-core:2.3.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.3.0'

And looks like some part of it uses Arrays.copyOf

Just opened a new ticket on fasterxml repo: Issue #131

Thanks for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants