CPD (copy/paste detector, mvn pmd:cpd with the CI configuration minimumTokens=50, PMD 7.7.0 on commit 255b812) reports 9 duplicated blocks, 421 duplicated lines. Almost all of it is the three sensor-record decoders copying each other.
Duplications
| Lines / tokens |
Files |
| 122 / 347 |
sdr/record/CompactSensorRecord.java:181 ↔ sdr/record/FullSensorRecord.java:246 |
| 75 / 164 |
sdr/record/EventOnlyRecord.java:145 ↔ sdr/record/FullSensorRecord.java:246 |
| 67 / 186 |
sdr/record/CompactSensorRecord.java:174 ↔ sdr/record/EventOnlyRecord.java:136 |
| 52 / 180 |
sdr/record/CompactSensorRecord.java:67 ↔ sdr/record/EventOnlyRecord.java:58 |
| 25 / 181 |
sdr/record/CompactSensorRecord.java:96 ↔ sdr/record/FullSensorRecord.java:107 |
| 24 / 162 |
sdr/record/EventOnlyRecord.java:88 ↔ sdr/record/FullSensorRecord.java:107 |
| 22 / 127 |
fru/ReadFruData.java:169 ↔ sdr/GetSdrRepositoryInfo.java:79 |
| 18 / 104 |
sel/GetSelEntry.java:105 ↔ session/SetSessionPrivilegeLevel.java:84 |
| 16 / 111 |
sdr/record/CompactSensorRecord.java:138 ↔ sdr/record/FullSensorRecord.java:137 |
Per pair: Compact ↔ Full 163 lines, Compact ↔ EventOnly 119 lines, EventOnly ↔ Full 99 lines.
Why it matters beyond the metric
FullSensorRecord, CompactSensorRecord and EventOnlyRecord share the same SDR "sensor record header" (owner ID/LUN/channel, sensor number, entity ID/instance, sensor type, event/reading type, ID string) plus the same getters/setters, but each has its own copy. Several of the decoding bugs found in the October 2026 review have to be fixed three times because of this (sensor owner/LUN handling #84, locator/ID-string parsing #86, reserved enum values #87), and the share-count expansion (#100) would have to be implemented twice.
Suggested fix
- Extract the common sensor-record header fields and their parsing into an intermediate abstract class (e.g.
AbstractSensorRecord extends SensorRecord) used by the three record types; keep only the type-specific bytes (thresholds/units/linearisation for Full, sharing for Compact/EventOnly) in the subclasses.
- Fold the 22-line and 18-line blocks (
GetSdrRepositoryInfo/ReadFruData timestamp-or-size parsing, GetSelEntry/SetSessionPrivilegeLevel response handling) into helpers in IpmiCommandCoder/TypeConverter.
- Add
pmd:cpd-check to the verify phase so new duplication fails the build.
CPD (copy/paste detector,
mvn pmd:cpdwith the CI configurationminimumTokens=50, PMD 7.7.0 on commit 255b812) reports 9 duplicated blocks, 421 duplicated lines. Almost all of it is the three sensor-record decoders copying each other.Duplications
sdr/record/CompactSensorRecord.java:181↔sdr/record/FullSensorRecord.java:246sdr/record/EventOnlyRecord.java:145↔sdr/record/FullSensorRecord.java:246sdr/record/CompactSensorRecord.java:174↔sdr/record/EventOnlyRecord.java:136sdr/record/CompactSensorRecord.java:67↔sdr/record/EventOnlyRecord.java:58sdr/record/CompactSensorRecord.java:96↔sdr/record/FullSensorRecord.java:107sdr/record/EventOnlyRecord.java:88↔sdr/record/FullSensorRecord.java:107fru/ReadFruData.java:169↔sdr/GetSdrRepositoryInfo.java:79sel/GetSelEntry.java:105↔session/SetSessionPrivilegeLevel.java:84sdr/record/CompactSensorRecord.java:138↔sdr/record/FullSensorRecord.java:137Per pair: Compact ↔ Full 163 lines, Compact ↔ EventOnly 119 lines, EventOnly ↔ Full 99 lines.
Why it matters beyond the metric
FullSensorRecord,CompactSensorRecordandEventOnlyRecordshare the same SDR "sensor record header" (owner ID/LUN/channel, sensor number, entity ID/instance, sensor type, event/reading type, ID string) plus the same getters/setters, but each has its own copy. Several of the decoding bugs found in the October 2026 review have to be fixed three times because of this (sensor owner/LUN handling #84, locator/ID-string parsing #86, reserved enum values #87), and the share-count expansion (#100) would have to be implemented twice.Suggested fix
AbstractSensorRecord extends SensorRecord) used by the three record types; keep only the type-specific bytes (thresholds/units/linearisation for Full, sharing for Compact/EventOnly) in the subclasses.GetSdrRepositoryInfo/ReadFruDatatimestamp-or-size parsing,GetSelEntry/SetSessionPrivilegeLevelresponse handling) into helpers inIpmiCommandCoder/TypeConverter.pmd:cpd-checkto theverifyphase so new duplication fails the build.