natural/java2python — Issue #5: AttributeError when attempting static access to Class.class
Author: karlrudd
Created: 2012-02-08 01:21:49+00:00
State: open

Given the following (simplified as much as possible) class definition:

```java
public class demoClass {
static Class klass = demoClass.class;
}
```

I get the following error:

```
$ j2py demoClass.java
Traceback (most recent call last):
File "/pathToPython/bin/j2py", line 258, in
sys.exit(runMain(configScript(sys.argv[1:])))
File "/pathToPython/bin/j2py", line 57, in runMain
return runOneOrMany(options)
File "/pathToPython/bin/j2py", line 82, in runOneOrMany
return runTransform(options)
File "/pathToPython/bin/j2py", line 134, in runTransform
module.walk(tree)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 86, in walk
visitor.walk(child, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 83, in walk
visitor = self.accept(tree, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 43, in accept
return call(node, memo)
File "/pathToPython/lib/python2.7/site-packages/java2python/compiler/visitor.py", line 121, in acceptType
name = node.firstChildOfType(tokens.IDENT).text
AttributeError: 'NoneType' object has no attribute 'text'
```
The original offending line is actually a call to Logger.getLogger, like so:

```java
private static Logger log = Logger.getLogger( aClassName.class );
```

In this case I can easily rewrite the Java code via search-and-replace or even comment the code out, but it would be nice to have this handled automatically.