Add java_fuzz_host example fuzz target

Bug: 201320878
Test: m example_java_fuzzer
Change-Id: Iad6e481a8b737353f20b4c6d4d0fb4f11fe65012
diff --git a/fuzzing/example_java_fuzzer/Android.bp b/fuzzing/example_java_fuzzer/Android.bp
new file mode 100644
index 0000000..a4a474d
--- /dev/null
+++ b/fuzzing/example_java_fuzzer/Android.bp
@@ -0,0 +1,30 @@
+// Copyright 2021, The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+java_fuzz_host {
+    name: "example_java_fuzzer",
+    srcs: ["ExampleFuzzer.java"],
+    static_libs: [
+        "jazzer",
+    ],
+    fuzz_config: {
+        fuzz_on_haiku_host: true,
+    },
+    corpus: ["testdata/*"],
+    dictionary: "example_java_fuzzer.dict",
+}
diff --git a/fuzzing/example_java_fuzzer/ExampleFuzzer.java b/fuzzing/example_java_fuzzer/ExampleFuzzer.java
new file mode 100644
index 0000000..d129376
--- /dev/null
+++ b/fuzzing/example_java_fuzzer/ExampleFuzzer.java
@@ -0,0 +1,25 @@
+// Copyright 2021, The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import com.code_intelligence.jazzer.api.FuzzedDataProvider;
+
+public class ExampleFuzzer {
+
+    public static void fuzzerTestOneInput(FuzzedDataProvider data) {
+        int magicNumber = 327;
+        if (data.consumeInt() == magicNumber) {
+          throw new UnsupportedOperationException("Fuzz error");
+        }
+    }
+}
\ No newline at end of file
diff --git a/fuzzing/example_java_fuzzer/example_java_fuzzer.dict b/fuzzing/example_java_fuzzer/example_java_fuzzer.dict
new file mode 100644
index 0000000..6edf100
--- /dev/null
+++ b/fuzzing/example_java_fuzzer/example_java_fuzzer.dict
@@ -0,0 +1 @@
+"TEST"
\ No newline at end of file
diff --git a/fuzzing/example_java_fuzzer/testdata/test.txt b/fuzzing/example_java_fuzzer/testdata/test.txt
new file mode 100644
index 0000000..30d74d2
--- /dev/null
+++ b/fuzzing/example_java_fuzzer/testdata/test.txt
@@ -0,0 +1 @@
+test
\ No newline at end of file