/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import org.json.JSONArray; class UnknownCallsTest { private int mBytesToRead; public void jsonArray_linear(JSONArray jsonArray) { int length = jsonArray.length(); for (int i = 0; i < length; ++i) {} } public void jsonArray_constant() { JSONArray jsonArray = new JSONArray(); jsonArray.put(1); for (int i = 0; i < jsonArray.length(); ++i) {} } public int read_sum_cost( InputStream in, byte[] buffer, int byteOffset, int byteCount, ArrayList list) throws IOException { int maxBytesToRead = Math.min(byteCount, mBytesToRead); int bytesRead = in.read(buffer, byteOffset, maxBytesToRead); for (int index = 0; index < bytesRead + maxBytesToRead; ++index) {} return 0; } // Expected: linear public int read_max_cost( InputStream in, byte[] buffer, int byteOffset, int byteCount, ArrayList list) throws IOException { int maxBytesToRead = Math.min(byteCount, mBytesToRead); int bytesRead = in.read(buffer, byteOffset, maxBytesToRead); if (bytesRead > 0) { maxBytesToRead = bytesRead + 1; } for (int index = 0; index < maxBytesToRead; ++index) {} return 0; } private static void loop_over_charArray(StringBuilder builder, String input) { for (Character c : input.toCharArray()) {} } private static void call_loop_over_charArray(StringBuilder out, String in) { loop_over_charArray(out, in); } // hashCode is impure but we don't invalidate all other library // calls such as size() void unmodeled_impure_linear(ArrayList list) { for (int i = 0; i < list.size(); i++) { list.get(i).hashCode(); } } int throw_exception() { throw new IllegalStateException(); } void call_throw_exception_linear() { for (int i = 0; i < throw_exception(); i++) {} } boolean unknown_bool; int may_throw_exception() { if (unknown_bool) { throw new IllegalStateException(); } else { return 10; } } void call_may_throw_exception_constant() { for (int i = 0; i < may_throw_exception(); i++) {} } abstract class AbstractC { abstract int[] abstract_func(); } void call_concrete_func_linear(AbstractC x) { int[] a = x.abstract_func(); for (int i = 0; i < a.length; i++) {} } }