This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

How can I check whether a class uses a particular other class?  RSS feed

 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In our application, we have a class doing debug-related stuff. Every call to it is supposed to be protected by a check of the value of a particular constant, set by generated code which is different, depending on whether the build is for debug or release purposes. The idea is that a release build will not use, or even load, the debug class.

This works fine, except when people forget to protect their code appropriately. Therefore, I would like to make a little tool, to run during the build process, to check whether we have successfully excluded the debug class.

The approach that currently seems most attractive is to look in each class file to see if there are any bytecodes that refer to the debug class. There shouldn't be any, for a release build.

Is this feasible? What would be the best way to examine the class file?

Any other ideas? I did a very quick program that did a rather dumb examination of the source. It was pretty good at spotting the mistakes, but created quite a lot of false positives (where it thought there was a mistake, but there wasn't really).
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what it's worth, if I had to do something like that, I would look at whether a byte code manipulation library like ASM or BCEL could help me.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose something like BCEL could be used, but it seems rather heavyweight, for my one, relatively simple requirement.
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!