Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection of unknown characters throws NullPointerException #1

Closed
abdolence opened this issue Feb 7, 2019 · 2 comments
Closed

Detection of unknown characters throws NullPointerException #1

abdolence opened this issue Feb 7, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@abdolence
Copy link

abdolence commented Feb 7, 2019

Thanks for a great work.
Bump into an issue with NPE.

Checked a problem with Unit Test:

import com.github.pemistahl.lingua.api.{Language, LanguageDetectorBuilder}
import org.scalatest._

class LanguageDetectTest extends FlatSpec with Matchers {

	val languageDetector = LanguageDetectorBuilder.
		fromLanguages(Language.ENGLISH,Language.GERMAN,Language.FRENCH).
		build()

	"A language detector" should "detect simple text" in {
		(languageDetector.detectLanguageOf("Hello").getIsoCode) should be("en")
	}

	it should "work without exception for weird texts and chars" in {
		noException shouldBe thrownBy {
			languageDetector.detectLanguageOf("""\_(ツ)_/¯""")
		}
	}
}

languageDetector.detectLanguageOf("""\_(ツ)_/¯""") - this is where NPE is occured.
This is a real text from user, actually :)

Callstack:

Caused by: kotlin.KotlinNullPointerException
	at com.github.pemistahl.lingua.api.LanguageDetector.getMostLikelyLanguage(LanguageDetector.kt:571)
	at com.github.pemistahl.lingua.api.LanguageDetector.detectLanguageOf(LanguageDetector.kt:88)

Thanks

@pemistahl pemistahl self-assigned this Feb 8, 2019
@pemistahl pemistahl added the bug Something isn't working label Feb 8, 2019
@pemistahl pemistahl changed the title NPE Detection of unknown characters throws NullPointerException Feb 8, 2019
@pemistahl
Copy link
Owner

Hi @abdmob, thank you for using my library and filing this bug report. I appreciate this a lot. 👍

You have found a serious bug, actually. Good catch! The NullPointerException is only thrown in those cases where the input string solely consists of letters that are unknown in any of the supported languages. I have just fixed this in release 0.3.2 with the commit 524e3eb. So please update.

I hope you still enjoy using my library. If you find any more issues, please do not hesitate to report them as well. Thank you and have a nice day.

@abdolence
Copy link
Author

That was fast, cheers! :)

PS. This issue is an example why in Scala we have maxByOption now BTW ;) I hope in Kotlin you have it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants