SearchSourceBuilder not functional on Android (Bug)

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:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method '' on a null object reference
   at org.elasticsearch.Build.getElasticsearchCodeSourceLocation(
   at org.elasticsearch.Build.<clinit>(
   at org.elasticsearch.common.logging.DeprecationLogger.<clinit>( 

The specific line of code which causes this NullPointerException is the following (

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

Apparently, per this StackOverflow answer, 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.


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

@DavidTurner WDYT?

1 Like

Opened an issue on GitHub, thanks for the tip!

Write Once Run Anywhere™ my foot :slight_smile:

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) 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.


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