Hi,
I’m reading successfully many datapoints like steps, water intake, hart rate, etc., but even when following the official tutorial for fetching the rich sleep data, I’m keep getting this error:
**
readData error callback (9003): com.samsung.android.sdk.health.data.error.PlatformInternalException: 9003: Internal error**
Here’s a detailed report:
**Samsung Health Data SDK - Sleep Data NullPointerException Bug Report**
## Issue Summary
**SDK Version**: samsung-health-data-api-1.0.0.aar
**Samsung Health Version**: 6.30.5.105
**Device**: Samsung Galaxy Z Fold4 (SM-F936B)
**Android Version**: 15
**Date Reported**: October 19, 2025
**Issue**: Reading sleep data via the Samsung Health Data SDK consistently fails with `NullPointerException: getString(…) must not be null` at the Samsung Health service level, even when following the official SleepDiary sample code exactly.
## Description
When attempting to read sleep data using `DataTypes.SLEEP.readDataRequestBuilder`, the Samsung Health service finds sleep records in its database (confirmed by cursor size > 0) but crashes during internal data processing with a null pointer exception. This occurs in the Samsung Health service code at `SleepHandlerHelper.getSleepMap()`, not in the application code.
### Error Details
```
E SHD#SleepDataTypeHandler: getMergedSleepRead: cursor size - 2
E SHD#HandlerHelper: exception message: getString(…) must not be null
E SHD#HandlerHelper: java.lang.NullPointerException: getString(…) must not be null
E SHD#HandlerHelper: at com.samsung.android.service.health.data.phd.util.CursorKt.getString(Unknown Source:20)
E SHD#HandlerHelper: at com.samsung.android.service.health.data.phd.handler.SleepHandlerHelper.getSleepMap(Unknown Source:95)
E SHD#HandlerHelper: at com.samsung.android.service.health.data.phd.handler.SleepDataTypeHandler.getMergedSleepRead(Unknown Source:116)
```
This results in:
```
E [SHD]SingleCallbackDistributor: readData error callback (9003)
com.samsung.android.sdk.health.data.error.PlatformInternalException: 9003: Internal error
```
## Reproduction Steps
### Code Implementation (Following Official SleepDiary Sample)
```kotlin
import com.samsung.android.sdk.health.data.HealthDataService
import com.samsung.android.sdk.health.data.request.DataTypes
import com.samsung.android.sdk.health.data.request.LocalTimeFilter
import com.samsung.android.sdk.health.data.request.ReadSourceFilter
import java.time.LocalDate
val store = HealthDataService.getStore(context)
val timeFilter = LocalTimeFilter.of(
LocalDate.now().atStartOfDay(),
LocalDate.now().plusDays(1).atStartOfDay()
)
// Attempt 1: WITH source filter (as per SleepDiary sample)
val readSourceFilter = ReadSourceFilter.fromPlatform()
val readRequest1 = DataTypes.SLEEP.readDataRequestBuilder
.setLocalTimeFilter(timeFilter)
.setSourceFilter(readSourceFilter)
.build()
val result1 = store.readData(readRequest1).dataList //
Fails with error 9003
// Attempt 2: WITHOUT source filter (to isolate issue)
val readRequest2 = DataTypes.SLEEP.readDataRequestBuilder
.setLocalTimeFilter(timeFilter)
.build()
val result2 = store.readData(readRequest2).dataList //
Also fails with error 9003
```
### Test Scenarios
1. **With original Samsung Health sleep data**:
Fails
2. **After deleting all sleep data**:
Fails when data re-appears
3. **With manually added sleep records**:
Fails
4. **Without source filter**:
Fails
5. **With source filter (fromPlatform)**:
Fails
6. **Different date ranges (today, yesterday)**:
Fails consistently
### Logs
Full logcat output showing the error:
```
10-19 12:15:44.498 D SamsungHealthData: ATTEMPT 1: Reading WITHOUT source filter…
10-19 12:15:44.498 D [SHD]HealthDataStoreAllImpl: readData invoked
10-19 12:15:44.500 I SHD#PrivilegedHealthService: xyz.angeloanan.healthconnectexports is verified
10-19 12:15:44.500 I SHD#PhdRequestAdapter: PHD9004 xyz.angeloanan.healthconnectexports Sleep
10-19 12:15:44.585 I SHD#SleepDataTypeHandler: getMergedSleepRead: cursor size - 2
10-19 12:15:44.586 E SHD#HandlerHelper: exception message: getString(…) must not be null
10-19 12:15:44.586 E SHD#HandlerHelper: java.lang.NullPointerException: getString(…) must not be null
10-19 12:15:44.586 E SHD#HandlerHelper: at com.samsung.android.service.health.data.phd.util.CursorKt.getString(Unknown Source:20)
10-19 12:15:44.586 E SHD#HandlerHelper: at com.samsung.android.service.health.data.phd.handler.SleepHandlerHelper.getSleepMap(Unknown Source:95)
10-19 12:15:44.586 E SHD#HandlerHelper: at com.samsung.android.service.health.data.phd.handler.SleepDataTypeHandler.getMergedSleepRead(Unknown Source:116)
```
## Analysis
### What’s Happening
1. Samsung Health **successfully finds** sleep records in its database (cursor size = 1 or 2)
2. When trying to convert the database cursor to a `HealthDataPoint` object, it calls `getString()` on a cursor column
3. That column contains `null` instead of the expected string value
4. The Kotlin code enforces non-null with `getString(…) must not be null`
5. This causes a `NullPointerException` in Samsung Health service code
### Root Cause
The sleep records in the Samsung Health database have **null values in required string fields**. Based on the stack trace location (`SleepHandlerHelper.getSleepMap`), this is likely one of:
- Device name/ID
- Source app identifier
- Sleep session metadata
- Other required string metadata fields
### Why This Happens
Possible causes:
1. **Samsung Health UI bug**: Manual sleep entry form doesn’t populate all required SDK fields
2. **Database migration issue**: Older sleep data not properly migrated to new schema
3. **Region/device-specific**: Some device models or regions don’t populate certain fields
4. **Incomplete data sync**: Sleep data from wearables missing required metadata
## Impact
- **Severity**: Critical - Completely blocks sleep data access via SDK
- **Scope**: Affects all sleep data retrieval attempts
- **Workaround**: None - no way to access sleep data through the official SDK
- **Other data types**: Steps, heart rate, water intake, nutrition, etc. all work fine - only sleep data affected
## Environment Details
### Device Information
```
Model: SM-F936B (Galaxy Z Fold4)
Product: q4qxeea
Android: 15
Samsung Health: 6.30.5.105 (versionCode: 6305105)
```
### SDK Details
```
Library: samsung-health-data-api-1.0.0.aar
Package: com.samsung.android.sdk.health.data
API Level: Latest public release
```
### Permissions
All required permissions granted:
```kotlin
Permission.of(DataTypes.SLEEP, AccessType.READ) // ✓ Granted
// Plus 11 other permissions for different data types - all working
```
## Expected Behavior
Based on the [official SleepDiary sample](https://developer.samsung.com/health/data/sample/sleep-diary.html), the code should:
1. Successfully read sleep data from Samsung Health
2. Return a list of `HealthDataPoint` objects with:
- Sleep score (`DataType.SleepType.SLEEP_SCORE`)
- Duration (`DataType.SleepType.DURATION`)
- Sessions (`DataType.SleepType.SESSIONS`)
- Sleep stages (Light, Deep, REM, Awake)
## Actual Behavior
Every attempt to read sleep data results in:
```
com.samsung.android.sdk.health.data.error.PlatformInternalException: 9003: Internal error
```
With the underlying cause being a `NullPointerException` in Samsung Health service code.
## Requested Fix
### Option 1: Fix Samsung Health Database (Preferred)
Ensure all sleep records have non-null values for required string fields, either by:
- Database migration to populate missing fields with default values
- Validation in Samsung Health app to prevent null fields
- Defensive null handling in `SleepHandlerHelper.getSleepMap()`
### Option 2: SDK Defensive Handling
Add null checks in the SDK service layer to:
- Skip records with null required fields
- Return partial data for valid records
- Provide meaningful error messages indicating which field is null
### Option 3: Documentation
If this is intentional behavior for certain regions/devices:
- Document which fields are required and which devices support them
- Provide device/region compatibility matrix
- Add error codes specific to “incomplete sleep data”
## Additional Information
### What Works
-
SDK connection and initialization
-
Permission requests and grants
-
Reading other data types (Steps, HeartRate, WaterIntake, etc.)
-
App verification by Samsung Health service
-
Sleep data cursor queries (finds records)
### What Fails
-
Converting sleep cursor data to SDK objects
-
Any `store.readData()` call for `DataTypes.SLEEP`
-
Both with and without `ReadSourceFilter`
-
All time ranges and date filters
### Reproduction Rate
**100%** - Every single attempt to read sleep data fails with the same error
## Developer Impact
This bug prevents developers from:
- Building health tracking apps that include sleep data
- Migrating from legacy Samsung Health SDK to new Data SDK
- Completing app features that require comprehensive health data export
- Following official Samsung Health Data SDK tutorials
## References
- [Samsung Health Data SDK Documentation]( https://developer.samsung.com/health/data )
- [SleepDiary Sample App](https://developer.samsung.com/health/data/sample/sleep-diary.html)
- [SDK Reference]( https://developer.samsung.com/health/data/api-reference )
```