# SearchSourceBuilder not functional on Android (Bug)

**URL:** <https://discuss.elastic.co/t/searchsourcebuilder-not-functional-on-android-bug/236946>\
**Category:** Elasticsearch\
**Created:** [June 12, 2020, 8:24pm UTC](https://discuss.elastic.co/t/searchsourcebuilder-not-functional-on-android-bug/236946 "2020-06-12T20:24:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhud](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jhud/32/70279_2.png) [@jhud](https://discuss.elastic.co/u/jhud)\
**Post date:** [June 12, 2020, 8:24pm UTC](https://discuss.elastic.co/t/searchsourcebuilder-not-functional-on-android-bug/236946/1 "2020-06-12T20:24:36Z")

</div>

Our team is trying to use the Elasticsearch Java High Level REST Client 7.7.1 on an Android device. So far we've only been indexing data, not querying, and that code has been functional. But when trying to simply _instantiate_ a `SearchSourceBuilder` object, the following error occurs:

```auto
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.security.CodeSource java.security.ProtectionDomain.getCodeSource()' on a null object reference
   at org.elasticsearch.Build.getElasticsearchCodeSourceLocation(Build.java:194)
   at org.elasticsearch.Build.<clinit>(Build.java:137)
   at org.elasticsearch.common.logging.DeprecationLogger.<clinit>(DeprecationLogger.java:154) 
   at org.elasticsearch.search.builder.SearchSourceBuilder.<clinit>(SearchSourceBuilder.java:83)

```

The specific line of code which causes this `NullPointerException` is the following (`Build.java:194`):

```auto
final CodeSource codeSource = Build.class.getProtectionDomain().getCodeSource();

```

Apparently, per [this StackOverflow answer](https://stackoverflow.com/questions/27790348/getclass-getprotectiondomain-getcodesource-getlocation-getpath-throw-a), the method `getProtectionDomain()` "is not implemented in Android's version of Java." `Build.class.getProtectionDomain()` thus returns null, hence the `NullPointerException`.

This would indicate that any classes which use the `DeprecationLogger`, such as the critically important `SearchSourceBuilder`, will not function on Android. This is an issue with the Java REST Client.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2020, 1:40am UTC](https://discuss.elastic.co/t/searchsourcebuilder-not-functional-on-android-bug/236946/2 "2020-06-13T01:40:28Z")

</div>

Welcome!

I think this would be great to open this discussion on elasticsearch GitHub repo as well.

@DavidTurner WDYT?

---

<div class="post-metadata">

**Author:** ![jhud](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jhud/32/70279_2.png) [@jhud](https://discuss.elastic.co/u/jhud)\
**Post date:** [June 13, 2020, 4:02am UTC](https://discuss.elastic.co/t/searchsourcebuilder-not-functional-on-android-bug/236946/3 "2020-06-13T04:02:27Z")

</div>

Opened an [issue on GitHub](https://github.com/elastic/elasticsearch/issues/58075), thanks for the tip!

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [June 13, 2020, 9:54am UTC](https://discuss.elastic.co/t/searchsourcebuilder-not-functional-on-android-bug/236946/4 "2020-06-13T09:54:05Z")

</div>

Write Once Run Anywhere™ my foot 🙂

I'm pretty sure we don't have any test infrastructure targeting Android, even for client libraries, so the answer may be that it's simply not a supported platform. If the only change needed is a null check here then that might fly (we added related null checks in [#27442](https://github.com/elastic/elasticsearch/pull/27442)) but who knows what other problems may be lurking for you down the line.

As a workaround you can use the low-level REST client and construct the request yourself.

Strange that this is the first time anyone has encountered this. I guess folk don't often expose Elasticsearch directly to mobile clients as you're doing, there's usually a webapp to mediate things. Anyway, thanks for opening the issue, it's definitely a valid one for us to discuss internally.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 11, 2020, 9:54am UTC](https://discuss.elastic.co/t/searchsourcebuilder-not-functional-on-android-bug/236946/5 "2020-07-11T09:54:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
