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

Issue with large number due to shell.evaluate under Eval.me #5

Closed
thelittlefireman opened this issue Aug 13, 2018 · 4 comments
Closed

Comments

@thelittlefireman
Copy link

return Eval.me(engine.createTemplate(codeTemplate).make(getMap()).toString())

i have huge issue with this script :

apply plugin: 'io.github.rockerhieu.versionberg'
versionberg {
    // Increase when you make incompatible API changes (default value is 0)
    major 25
    minor 1
        nameTemplate 'V01.${major}${minor}-${commitSha}-${new Date().format("dd_MM_yyyy")}'
    codeTemplate '${major}*(100000000) + ${minor}*(10000) +${build}'
}

it always return negative value due tu integer overflow

after some reseach and test on https://groovyconsole.appspot.com/

the codeTemplate is working when you add L at the end of large number :
'25*(100000000) + 1*(10000) +1198' = -1794956098
'25*(100000000L) + 1*(10000L) +1198' = 2500011198

i try : codeTemplate '${major}*(100000000L) + ${minor}*(10000L) +${build}' but doesn't work i still got negative value. 😕

Any help, or ideas ?

thanks
thomas

@rockerhieu
Copy link
Owner

How about reducing 100000000 and 10000? I could use Long to hold the value of versionberg.code but it won't be compatible with Android's versionCode.

@thelittlefireman
Copy link
Author

thelittlefireman commented Aug 14, 2018

Thanks you for your answer. I can't because I already publish apk with a high versionCode. I think the real question is why "codeTemplate '${major}(100000000) + ${minor}(10000) +${build}'" return a negative number ? because 25 * 100000000+1 * 10000 + 1197 < 2,147,483,647 (Integer Max value)

@rockerhieu
Copy link
Owner

That's interesting indeed, let me check.

@rockerhieu
Copy link
Owner

rockerhieu commented Aug 14, 2018

@thelittlefireman have you tried to execute this on the groovy console?

print((int) 2500011198)

And 2500011198 is clearly greater than Integer.MAX_VALUE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants