Skip to content

Commit d0a7db5

Browse files
nbradburyclaude
andauthored
Fix Sentry 31NG/368D/31G1: skip Gutenberg media-URL replacement when remote mediaId is null (#22871)
BlockProcessor reads MediaFile.mediaId as a non-null Kotlin String at the field initializer, but MediaFile is a Java helper whose mediaId is null whenever the underlying MediaModel has no remote ID (set explicitly in FluxCUtils.mediaFileFromMediaModel). Guard the single entry point that constructs MediaUploadCompletionProcessor so the substitution is skipped instead of crashing: with no remote ID there is nothing to substitute. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b4c8f1a commit d0a7db5

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

WordPress/src/main/java/org/wordpress/android/ui/posts/PostUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ public static boolean shouldShowGutenbergEditor(boolean isNewPost, String postCo
428428
public static String replaceMediaFileWithUrlInGutenbergPost(@NonNull String postContent,
429429
@NonNull String localMediaId, MediaFile mediaFile,
430430
@NonNull String siteUrl) {
431-
if (mediaFile != null && contentContainsGutenbergBlocks(postContent)) {
431+
// BlockProcessor reads MediaFile.mediaId as a non-null Kotlin String and would NPE;
432+
// with no remote ID there is nothing to substitute, so leave the content untouched.
433+
if (mediaFile != null && mediaFile.getMediaId() != null
434+
&& contentContainsGutenbergBlocks(postContent)) {
432435
MediaUploadCompletionProcessor processor = new MediaUploadCompletionProcessor(localMediaId, mediaFile,
433436
siteUrl);
434437
postContent = processor.processContent(postContent);

WordPress/src/test/java/org/wordpress/android/ui/posts/PostUtilsUploadProcessingTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,14 @@ class PostUtilsUploadProcessingTest {
6161
)
6262
Assertions.assertThat(processedContent).isEqualTo(TestContent.newMediaTextBlockWithVideo)
6363
}
64+
65+
@Test
66+
fun `replaceMediaFileWithUrlInGutenbergPost leaves content unchanged when mediaId is null`() {
67+
whenever(mediaFile.mediaId).thenReturn(null)
68+
val processedContent = PostUtils.replaceMediaFileWithUrlInGutenbergPost(
69+
TestContent.oldImageBlock,
70+
TestContent.localMediaId, mediaFile, TestContent.siteUrl
71+
)
72+
Assertions.assertThat(processedContent).isEqualTo(TestContent.oldImageBlock)
73+
}
6474
}

0 commit comments

Comments
 (0)