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 415439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:22:53+00:00 2026-05-12T18:22:53+00:00

I have a variable that very rarely gets an incorrect value. Since the system

  • 0

I have a variable that very rarely gets an incorrect value. Since the system is quite complex I’m having trouble tracing all the code paths that value goes through – there are multiple threads involved, it can be saved and then loaded from a DB and so on. I’m going to try to use a code graph generator to see if I can spot the problem by looking at the ways the setter can be called, by may be there’s some other technique. Perhaps wrapping the value with a class that traces the places and changes it goes through? I’m not sure the question is clear enough, but I’d appreciate input from somebody who encountered such a situation.

[Edit] The problem is not easily reproducible and I can’t catch it in a debugger. I’m looking for a static analysis or logging technique to help track down the issue.

[Edit 2] Just to make things clearer, the value I’m talking about is a timestamp represented as the number of milliseconds from the Unix epoch (01/01/1970) in a 64-bit long variable. At some unknown point the top 32 bits of the value are truncated generating completely incorrect (and unrecoverable) timestamps.

[Edit 3] OK, thanks to some of your suggestions and to a couple of hours of pouring through the code, I found the culprit. The millisecond-based timestamp was converted into a second-based timestamp by dividing it by 1000 and stored in an int variable. At a later point in code, the second-based timestamp (an int) was multiplied by 1000 and stored into a new long variable. Since both 1000 and the second-based timestamps were int values, the result of the multiplication was truncated before being converted to long. This was a subtle one, thanks to everyone who helped.

  • 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-05-12T18:22:53+00:00Added an answer on May 12, 2026 at 6:22 pm

    If you are using a setter and only a setter to set your value you can add these lines in order to track the thread and stack trace:

    public void setTimestamp(long value) {
      if(log.idDebugEnabled) {
        log.debug("Setting the value to " + value + ". Old value is " + this.timestamp);
        log.debug("Thread is " + Thread.currentThread().getName());
        log.debug("Stacktrace is", new Throwable()); // we could also iterate on Thread.currentThread().getStackTrace()
      }
      // check for bad value
      if(value & 0xffffffff00000000L == 0L) {
        log.warn("Danger Will Robinson", new IlegalValueException());
      }
      this.timestamp = value;
    }
    

    Also, go over the class that contains the field, and make sure that every reference to it is done via the setter (even in private/protected methods)

    Edit

    Perhaps FindBugs can help in terms of static analysis, I’ll try to find the exact rule later.

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

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do tables or the entire database. For a… May 14, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer I evaluated the use of markdown in PHP some weeks… May 14, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer Did you create a custom errors section in your web.config?… May 14, 2026 at 4:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.