Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,19 @@ public Field getField(String name) throws NoSuchFieldException, SecurityExceptio
public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
return new Method(this, name, parameterTypes);
}

/**
* Returns the {@code Class} representing the component type of an
* array. If this class does not represent an array class this method
* returns null.
*
* @return the {@code Class} representing the component type of this
* class if this class is an array
* @see java.lang.reflect.Array
* @since 1.1
*/
public Class<?> getComponentType() {
CProver.notModelled();
return CProver.nondetWithoutNullForNotModelled();
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/cprover/CProver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.BufferedInputStream;
import java.io.PrintStream;
import java.lang.reflect.Array;

public final class CProver
{
Expand Down Expand Up @@ -350,4 +351,18 @@ public static float doubleToFloat(double d)
CProver.assume(d == (double) converted);
return converted;
}

/**
* Instantiates (but does not populate) an array with type matching a given array,
* but with a potentially different length. Used by ArrayList.toArray, for example,
* whose internal array is an Object[] but must provide that array as a user-supplied
* T[], copying the runtime type of whatever array the user provided as a template.
*
* The implementation given here is correct, but JBMC cannot currently understand these
* reflective methods and therefore replaces this function with its own implementation.
*/
public static <T> T[] createArrayWithType(int length, T[] type) {
Class typeClass = type.getClass();
return (T[])Array.newInstance(typeClass.getComponentType(), length);
}
}