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

  • Home
  • SEARCH
  • 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 333383
In Process

The Archive Base Latest Questions

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

I’m searching a way to include __LINE__ as a compile-time constant in outputted messages.

  • 0

I’m searching a way to include __LINE__ as a compile-time constant in outputted messages.

Various solutions seem to exist, but with a big runtime penalty as suggested in __LINE__ in JS and __LINE__ in C#. They are usually always based upon a runtime object StackFrame as log4j.

Using the log4j possibility of enabling/disabling on a needed basis isn’t an option either since usually when an error happens, it’s too late to enable the line numbers, and inlined code doesn’t seem to have any line numbers any more.
. Would it be possible to either :

  1. Pre-process the java source files before compilation, ideally with something integrated with Eclipse1, so the it can be tested on the developpement platform also.
  2. Be able to pre-process the class at loading time. The overhead would then be negligible by being amortized.

1. Actually I do use an ugly hack: calling a custom preprocessor just after checkout on the build server via ANT tricks

  • 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-12T09:57:23+00:00Added an answer on May 12, 2026 at 9:57 am

    If you compile with the debug=line option, the line information exists in the class file but the VM can throw that away at runtime. This depends on some options which you can specify when you start the Java program. Usually, the performance penalty for running with debug infos is around 5% plus a bit more memory in the perm gen space. Since this information is so invaluable, I see no reason to strip this information.

    Your comment (Util.java(Inlined Compiled Code)) suggest that you’re using aggressive optimizations. If you can, turn those off. That way, you can simply:

    // For Java 1.4, use new Exception().getStackTrace()
    int line = Thread.currentThread().getStackTrace()[0].getLineNumber();
    

    when you need it (i.e. inside of catch or if (log.isInfoEnabled())).

    As for __LINE__, the Java compiler has no support for this. Your only option is to use some hacks to filter the source. I suggest to define a variable int __LINE__ somewhere and set that to some random value (0 being random enough) when you need it. Then write a filter that replaces the number in __LINE__ = \d+ with the current line number. This allows to fix the line number in place.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.