hiero-ledger / hiero-ledger/hiero-consensus-node

Add parameterized type to SchemaRegistry in Service interface

Open Beginner friendly
#21,922 4 comments 0 reactions 0 assignees View on GitHub
Good First Issue
Dominant language
Java
Stars
406
Forks
226
Avg merge
3d 4h
Merged PRs (30d)
210

Description

## Summary

The `Service` interface should use `SchemaRegistry` instead of raw `SchemaRegistry` type to provide type safety when registering schemas.

## Current Situation

Currently, the `Service` interface uses a raw `SchemaRegistry` type:

```java
public interface Service {
/**
* Registers the schemas this application state really uses with the given {@link SchemaRegistry}.
*
* @param registry the registry to register the schemas with
*/
void registerSchemas(@NonNull SchemaRegistry registry);
}
```

However, `SchemaRegistry` is a generic type that should be parameterized with a version type:

```java
public interface SchemaRegistry {
SchemaRegistry register(@NonNull Schema schema);
}
```

Using the raw type creates a type safety issue where there's no compile-time verification that schemas being registered match the expected version type.

## Proposed Solution

Change the `Service` interface to use the parameterized type:

```java
public interface Service {
/**
* Registers the schemas this application state really uses with the given {@link SchemaRegistry}.
*
* @param registry the registry to register the schemas with
*/
void registerSchemas(@NonNull SchemaRegistry registry);
}
```

## Benefits

1. **Type Safety**: Compile-time verification that all schemas use `SemanticVersion`
2. **Better IDE Support**: Auto-completion and type inference work correctly
3. **Consistency**: All Hedera services use `SemanticVersion` for schema versioning
4. **Catches Errors Early**: Prevents accidentally using wrong version type

## Related Code

- `Service` interface: `platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/lifecycle/Service.java` (line 43)
- `SchemaRegistry` interface: `platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/lifecycle/SchemaRegistry.java`
- `SemanticVersion`: `hapi/hedera-protobufs/services/basic_types.proto`

## Migration Notes

This is a source-compatible change - existing implementations will continue to compile without modification. The change only adds type information that was previously implicit.

Contributor guide

Open the contributing guide

Research direction

Start with platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/lifecycle/Service.java and inspect SchemaRegistry.java, then check implementations and call sites of registerSchemas. Update the interface to carry SemanticVersion through SchemaRegistry and confirm the state API builds and its relevant tests pass without raw-type warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.