Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7769389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:08:51+00:00 2026-06-01T16:08:51+00:00

Findbugs gives me for public GsmSignalStrength clone() following warning: Class defines clone() but doesn’t

  • 0

Findbugs gives me for public GsmSignalStrength clone() following warning:
Class defines clone() but doesn’t implement Cloneable.

Why do I have to implement Cloneable? Is it because of shallow and deep copy? I have to apologize for my bad Java skills, but I’m a Java newbie.

Here is my code:

class GsmSignalStrength
{
    static final byte SIGNAL_STRENGTH_UNKNOWN = 99;
    static final byte SIGNAL_STRENGTH_1 = 1;
    static final byte SIGNAL_STRENGTH_2 = 2;
    static final byte SIGNAL_STRENGTH_3 = 3;
    static final byte SIGNAL_STRENGTH_4 = 4;
    static final byte SIGNAL_STRENGTH_5 = 5;

    /* Constructors */

    GsmSignalStrength(byte signalStrength)
    {
        initClassVars(signalStrength);
    }

    GsmSignalStrength()
    {
        initClassVars(SIGNAL_STRENGTH_UNKNOWN);
    }

    GsmSignalStrength(byte[] serializedData, IntClass deserializationIndex)
    {
        initClassVars(SIGNAL_STRENGTH_UNKNOWN);
        setClassProperties(serializedData, deserializationIndex);
    }

    byte value;

    /* Methods */

    public void copyTo(GsmSignalStrength destination)
    {
        destination.value = this.value;
    }

    public GsmSignalStrength clone()
    {
        GsmSignalStrength clonedValue = new GsmSignalStrength();

        this.copyTo(clonedValue);

        return clonedValue;
    }

    private void initClassVars(byte signalStrength)
    {
        this.value = signalStrength;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:08:52+00:00Added an answer on June 1, 2026 at 4:08 pm

    Cloneable is not needed here.

    This is because your implementation of clone() does not actually clone the object. In Java, cloning specifically means using Object.clone(), which does JVM magic to copy the object. Although your code does something sort of equivalent to cloning (and better, IMHO – it avoids using magic), it is not true cloning.

    However, findbugs doesn’t know that, so it’s worried that you might be trying to clone a non-Cloneable object.

    One solution here might be to rename your method to something else (copy()?), so it doesn’t appear to be a clone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code piece that I am reviewing (using FindBugs ). public class
I have the following ( doctored ) class in a system I'm working on
In my findbugs report I have a SIO_SUPERFLUOUS_INSTANCEOF correctness error in the following code
I have code like this: public class Thingy { private final Lock lock =
Why do FindBugs raises me the following warning: Possible null pointer dereference . current
Findbugs bugs me about a method which opens two Closeable instances, but I can't
I want my findbugs report not show the following error: DM_NUMBER_CTOR: Method invokes inefficient
I want to run FindBugs on a project, but we're still stuck with Java
I have experimented with several different static analyzers for Java, notably Findbugs and PMD.
This is my class (JAX-RS annotated): @Path(/) public class Foo { @Context private UriInfo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.