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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:17:03+00:00 2026-06-12T19:17:03+00:00

I ran into a problem using java objects in jython today because jython is

  • 0

I ran into a problem using java objects in jython today because jython is trying to be intelligent and automatically creates properties for (simple) getter/setter methods – For each method a field with the leading get/set removed and the next letter converted to lowercase is created:

//java code
class MyClass {
    public List<Thing> getAllThings() { ... }
    public List<Thing> getSpecificThings(String filter) { ... }
    public void setSomeThing(SomeThing x) { ... }
    [...]
}

#jython code
obj = MyClass()
hasattr(obj, "allThings") #-> True
hasattr(obj, "specificThings") #-> False because getSpecificThings has a param
hasattr(obj, "someThing") #-> False BUT
"someThing" in dir(obj)   #-> True

The last line summarizes my problem here – the result of dir contains these fields (even when executed on obj.class instead of obj). I need a list of all methods callable on the object, which for my objects basically is the result of dir without these properties and filtered to exclude everything inherited from java.lang.Object and things starting with an underscore (the purpose of this is to automagically convert some python classes to java equivalents, e.g. dicts to Maps). In theory I could use __dict__ which doesn’t contain them, but this would mean I’d have to recursively evaluate the base classes’ __dict__s too, which I would like to avoid. What I am currently doing is seeing if the attribute actually exists and then check if it has an argslist attribute (meaning it is a method), which is true for every dir entry except for the generated properties:

for entry in dir(obj):
    #skip things starting with an underscore or inherited from Object
    if entry.startswith("_") or entry in dir(java.lang.Object): continue
    #check if the dir entry is a fake setter property
    if not hasattr(obj, entry): continue
    #check if the dir entry has an argslist attribute (false for getter props)
    e = getattr(obj, entry)
    if not hasattr(e, "argslist"): continue
    #start actual processing of the entry...

The problem with this approach is that the objects in question are interfaces to beans and a getSomething method typically fetches data from a database, so the getattr call for a property makes a roundtrip to the DB which can take multiple seconds and waste tons of memory.

Can I stop jython from generating these properties? If not, does anybody have an idea how I can filter out the properties without accessing them first? The only thing I could think of was checking if dir contains a method named get/set<property>, but this seems hackish and could generate false positives, which must be avoided.

  • 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-12T19:17:04+00:00Added an answer on June 12, 2026 at 7:17 pm

    The answer was easier than anticipated. While a hasattr of the property is True for an object instance, it is False for the objects class if the get-method in question is not static – the class doesn’t have the property as you can’t execute the method on it. The updated loop now looks like this:

    for entry in dir(obj):
        #skip things starting with an underscore or inherited from Object
        if entry.startswith("_") or entry in dir(java.lang.Object): continue
        #check if the dir entry is a fake property
        if not hasattr(obj.class, entry): continue
        #check if the dir entry has an argslist attribute (false if not a method)
        e = getattr(obj, entry)
        if not hasattr(e, "argslist"): continue
        #start actual processing of the entry...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem today trying to override an implementation of an interface
While trying to zip an archive using the java.util.zip I ran into a lot
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
while working on a school project i ran into a problem using javascript to
I am building a form using a js+html and I ran into a problem.
I ran in to an interesting problem while using the 'tap' method on objects
I ran into a strange problem using a C# webservice client to call a
I'm trying to create a proper regex for my problem and apparently ran into
I recently ran into a problem caused by using fstream::eof(). I read the following
I ran into the following problem using spring-security 3.0.3 with jersey 1.2: when i

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.