• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oracle / opengrok / #3715

30 Nov 2023 08:55AM UTC coverage: 75.937% (+9.8%) from 66.106%
#3715

push

web-flow
Refactoring to reduce sonar code smell fixes (#4485)

---------

Signed-off-by: Gino Augustine <ginoaugustine@gmail.com>
Co-authored-by: Vladimir Kotal <vlada@kotalovi.cz>

397 of 478 new or added lines in 51 files covered. (83.05%)

50 existing lines in 22 files now uncovered.

44494 of 58593 relevant lines covered (75.94%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/suggester/src/main/java/org/opengrok/suggest/popular/impl/chronicle/BytesRefSizedReader.java
1
/*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License (the "License").
6
 * You may not use this file except in compliance with the License.
7
 *
8
 * See LICENSE.txt included in this distribution for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing Covered Code, include this CDDL HEADER in each
12
 * file and include the License file at LICENSE.txt.
13
 * If applicable, add the following below this CDDL HEADER, with the
14
 * fields enclosed by brackets "[]" replaced with your own identifying
15
 * information: Portions Copyright [yyyy] [name of copyright owner]
16
 *
17
 * CDDL HEADER END
18
 */
19

20
/*
21
 * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
 */
23
package org.opengrok.suggest.popular.impl.chronicle;
24

25
import net.openhft.chronicle.bytes.Bytes;
26
import net.openhft.chronicle.core.io.IORuntimeException;
27
import net.openhft.chronicle.core.util.ReadResolvable;
28
import net.openhft.chronicle.hash.serialization.SizedReader;
29
import net.openhft.chronicle.wire.Marshallable;
30
import net.openhft.chronicle.wire.WireIn;
31
import net.openhft.chronicle.wire.WireOut;
32
import org.apache.lucene.util.BytesRef;
33
import org.jetbrains.annotations.NotNull;
34
import org.jetbrains.annotations.Nullable;
35

36
import java.util.Optional;
37

38
/**
39
 * {@link BytesRef} data serializer for {@link net.openhft.chronicle.map.ChronicleMap}.
40
 * Modified from <a href="https://github.com/OpenHFT/Chronicle-Map/blob/master/docs/CM_Tutorial_DataAccess.adoc">...</a>
41
 */
42
@SuppressWarnings("java:S6548")
43
public class BytesRefSizedReader implements SizedReader<BytesRef>, Marshallable, ReadResolvable<BytesRefSizedReader> {
44

45
    public static final BytesRefSizedReader INSTANCE = new BytesRefSizedReader();
1✔
46

47
    private BytesRefSizedReader() {
48
    }
49

50
    @NotNull
51
    @Override
52
    @SuppressWarnings({"rawtypes"})
53
    public BytesRef read(Bytes in, long size, @Nullable BytesRef using) {
54
        if (size < 0L || size > Integer.MAX_VALUE) {
1✔
55
            throw new IORuntimeException("byte[] size should be non-negative int, " +
×
56
                    size + " given. Memory corruption?");
57
        }
58
        int arrayLength = (int) size;
1✔
59
        using = Optional.ofNullable(using)
1✔
60
                .orElseGet( () ->
1✔
61
                        new BytesRef(new byte[arrayLength])
1✔
62
                );
63
        if (using.bytes.length < arrayLength) {
1✔
UNCOV
64
            using.bytes = new byte[arrayLength];
×
65
        }
66
        in.read(using.bytes, 0, arrayLength);
1✔
67
        using.offset = 0;
1✔
68
        using.length = arrayLength;
1✔
69
        return using;
1✔
70
    }
71

72
    @Override
73
    public void writeMarshallable(@NotNull WireOut wireOut) {
74
        // no fields to write
75
    }
1✔
76

77
    @Override
78
    public void readMarshallable(@NotNull WireIn wireIn) {
79
        // no fields to read
80
    }
1✔
81

82
    @NotNull
83
    @Override
84
    public BytesRefSizedReader readResolve() {
85
        return INSTANCE;
1✔
86
    }
87

88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc