From e64513bf4ecce60aff5c04e3bed91b203429d12f Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 8 Nov 2024 04:57:15 -0800 Subject: [PATCH] RNGP - Do not attempt to substring to 1024 while logging. (#47509) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47509 Fixes https://github.com/facebook/react-native/issues/47504 Changelog: [Android] [Fixed] - RNGP - Do not attempt to substring to 1024 while logging Reviewed By: javache Differential Revision: D65659586 fbshipit-source-id: 8fa16131cea96b8b6aa9c0224c7b990a4f51175f --- .../kotlin/com/facebook/react/ReactSettingsExtension.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt b/packages/gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt index be26a223379..aea525747e0 100644 --- a/packages/gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt +++ b/packages/gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt @@ -15,6 +15,7 @@ import java.math.BigInteger import java.security.MessageDigest import java.util.concurrent.TimeUnit import javax.inject.Inject +import kotlin.math.min import org.gradle.api.GradleException import org.gradle.api.file.FileCollection import org.gradle.api.initialization.Settings @@ -159,7 +160,10 @@ abstract class ReactSettingsExtension @Inject constructor(val settings: Settings val logger = Logging.getLogger("ReactSettingsExtension") logger.error(message) if (cacheJsonConfig.length() != 0L) { - logger.error(cacheJsonConfig.readText().substring(0, 1024)) + logger.error( + cacheJsonConfig + .readText() + .substring(0, min(1024, cacheJsonConfig.length().toInt()))) } cacheJsonConfig.delete() throw GradleException(message)