You shouldn't really force the numPartitions parameter here if none is given, but just maintain the old behavior of calling the underlying Scala implementation without supplying numPartitions.  What you have now is code duplication -- which works the same as the Scala at present, but will introduce unexpectedly divergent behavior if the handling of the default evaluation of numPartitions is ever changed in the Scala implementation of sortByKey.