public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* [4.8 Regression] gjavah throws an exception
@ 2012-12-17 15:39 Andrew Haley
  2012-12-17 18:38 ` [cp-patches] " Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Haley @ 2012-12-17 15:39 UTC (permalink / raw)
  To: classpath-patches, java

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55716

This bug is caused by http://cvs.savannah.gnu.org/viewvc/classpath/tools/gnu/classpath/tools/javah/Main.java?root=classpath&r1=1.13&r2=1.14

Automagic handling of inner classes was added, but in a bogus way.
If a class has inner classes, those inner classes are searched on
the classpath.  This is wrong if the argument to javah is a filename:
the inner class may not exist on the classpath, and even if they do
they will be the wrong versions.

IMO, if given filenames gjavah should not search for inner classes
at all.  This patch does so.

I have another patch that finds the correct inner class files for a
a class, but this is better.  As a whitespace diff it is simply

Index: Main.java
===================================================================
--- Main.java	(revision 194553)
+++ Main.java	(working copy)
@@ -370,6 +370,8 @@
         results.put(filename, klass);
         parsed.add(item.toString());

+        if (! (item instanceof File))
+          {
         // Check to see if there are inner classes to also parse
         Iterator<?> innerClasses = klass.innerClasses.iterator();
         HashSet<Object> innerNames = new HashSet<Object>();
@@ -381,6 +383,7 @@
           }
         results.putAll(parseClasses(innerNames.iterator()));
       }
+      }
     return results;
   }

Andrew.


2012-12-17  Andrew Haley  <aph@redhat.com>

	* tools/gnu/classpath/tools/javah/Main.java (parseClasses): Dont
	scan inner classes if our item is a file.

Index: Main.java
===================================================================
--- Main.java	(revision 194553)
+++ Main.java	(working copy)
@@ -370,16 +370,19 @@
         results.put(filename, klass);
         parsed.add(item.toString());

-        // Check to see if there are inner classes to also parse
-        Iterator<?> innerClasses = klass.innerClasses.iterator();
-        HashSet<Object> innerNames = new HashSet<Object>();
-        while (innerClasses.hasNext())
+        if (! (item instanceof File))
           {
-            String innerName = ((InnerClassNode) innerClasses.next()).name;
-            if (!parsed.contains(innerName))
-              innerNames.add(innerName);
+            // Check to see if there are inner classes to also parse
+            Iterator<?> innerClasses = klass.innerClasses.iterator();
+            HashSet<Object> innerNames = new HashSet<Object>();
+            while (innerClasses.hasNext())
+              {
+                String innerName = ((InnerClassNode) innerClasses.next()).name;
+                if (!parsed.contains(innerName))
+                  innerNames.add(innerName);
+              }
+            results.putAll(parseClasses(innerNames.iterator()));
           }
-        results.putAll(parseClasses(innerNames.iterator()));
       }
     return results;
   }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [cp-patches] [4.8 Regression] gjavah throws an exception
  2012-12-17 15:39 [4.8 Regression] gjavah throws an exception Andrew Haley
@ 2012-12-17 18:38 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2012-12-17 18:38 UTC (permalink / raw)
  To: Andrew Haley; +Cc: classpath-patches, java

On Mon, 2012-12-17 at 15:39 +0000, Andrew Haley wrote:
> If a class has inner classes, those inner classes are searched on
> the classpath.  This is wrong if the argument to javah is a filename:
> the inner class may not exist on the classpath, and even if they do
> they will be the wrong versions.
> 
> IMO, if given filenames gjavah should not search for inner classes
> at all.  This patch does so.
> [...]
> 2012-12-17  Andrew Haley  <aph@redhat.com>
> 
> 	* tools/gnu/classpath/tools/javah/Main.java (parseClasses): Dont
> 	scan inner classes if our item is a file.

That looks right to me. As you said on irc, no other javah
implementation seems to support "raw class files" as input. Others only
seem to accept class names. So there is no "best practice" to follow in
this case. Not trying to search for inner classes when a class file is
provided seems a good choice since at the bytecode level there really
isn't such a thing as an inner class (just funnily named classes).

Thanks,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-17 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-17 15:39 [4.8 Regression] gjavah throws an exception Andrew Haley
2012-12-17 18:38 ` [cp-patches] " Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).