Static import of member of class in same unnamed package fails

I think I found a bug in the JDK 1.5 (Tiger) javac compiler. It involves static import and unnamed packages.
Consider the following compilation unit:
import static D.x;
class C {
    int foo() { return x; }
class D {
    static final int x = 1;
}Running javac from the Tiger beta 2 SDK generates the following output:
Test.java:1: cannot find symbol
symbol: class D
import static D.x;
              ^
Test.java:1: static import only from classes and interfaces
import static D.x;
^
Test.java:4: cannot find symbol
symbol  : variable x
location: class C
    int foo() { return x; }
                       ^
3 errorsIn my opinion, this is a bug. This compilation unit should compile without errors.
Note that the following compilation unit compiles without errors with Tiger beta 2:
package p;
import static p.D.x;
class C {
    int foo() { return x; }
class D {
    static final int x = 1;
}Note that this issue is distinct from the issue of importing a class from an unnamed package into a named package. I totally agree that the latter is not allowed. However, the current issue is a different matter, since here I am importing members from the same package (which happens to be an unnamed package).

The unnamed package feature is deprecated. Even if this is a bug (which I sort of doubt), this may never be fixed.

Similar Messages

  • BUG: JDeveloper code editor shows valid static import call as error

    I've noticed what appears to be a bug in the JDeveloper code validator when dealing with static imports.
    The following classes demonstrate the problem:
    package test;
    public class Parent {
      public static void parentMethod() {
        System.out.println("called parentMethod.");
    package test;
    public class Child extends Parent {
      public static void childMethod() {
        System.out.println("called childMethod.");
    package test;
    import static test.Child.*;
    public class StaticInheritanceTest {
      public static void main(String[] args) {
        Child.childMethod();
        Child.parentMethod();
        childMethod();
        parentMethod();  //<-- this line is highlighted as an error
    }Notice how on lines 7 and 8 of StaticInheritanceTest, the code validator does recognise that both parentMethod and childMethod are static methods of the Child class.
    Since 'Child' has been statically imported, then parentMethod should be available. Although parentMethod is presented as an 'auto-suggest' at line 11 in StaticInheritanceTest, when you try to call it the code editor shows the call as an error and the Ctrl-Click (to drill down into the method) doesn't work.
    When I run the class, it compiles successfully and runs with the following output:
    called childMethod.
    called parentMethod.
    called childMethod.
    called parentMethod.This might seem like an obscure and theoretical problem, but I've hit this whilst using Mockito, which uses exactly this kind of inherited static method to provide matchers.

    Hi,
    thanks. Will file a bug. This seems to be a designtime only issue that does not present a show stopper.
    Frank

  • Clashes with class of same name: weblogic 6.0 sp2

              Hi Mike,
              Thanks for the response.
              I am getting this error
              C:\bea\testDir\jsp_servlet\_vgn\_portal\_system\_site\_edit.java:7: package jsp_servlet._vgn._portal._system
              clashes with class of same name
              Full compiler error(s): C:\bea\testDir\jsp_servlet\_vgn\_portal\_system\_site\_edit.java:7:
              package jsp_servlet._vgn._portal._system clashes with class of same name package
              jsp_servlet._vgn._portal._system._site; ^ 1 error
              This is the error on the screen and the messages I posted are from the weblogic.log
              Let me know if you need more info. Also, i found some suggestion somewhere that
              I should install rolling patch 2, bu i searched the downloads and did not find
              anything called Rolling Patch 2.
              Varun
              (No more information available, probably caused by another error) Michael Young
              <[email protected]> wrote:
              >Hi.
              >
              >Can you post the complete error? I don't see anything about class name
              >clashes in the exception you posted below.
              >
              >Cheers,
              >Michael
              >
              >Varun Garg wrote:
              >
              >> I am getting a "clashes with class of same name" error with some of
              >my jsp pages
              >> on weblogic 6.0 sp2. I have tried deleting my temporary jsp file, i
              >have tried
              >> using a working directory for the jsp using weblogic.xml.
              >>
              >> This happens for few files and not all of them
              >>
              >> java.io.IOException: Compiler failed executable.exec(java.lang.String[javac,
              >-classpath,
              >> C:\bea\wlserver6.0\config\mydomain\applications\DefaultWebApp_myserver;C:\bea\wlserver6.0\.\config\mydomain\applications\DefaultWebApp_myserver\WEB-INF\lib\ASTab.jar;C:\bea\testDir;C:\bea\jdk130\jre\lib\rt.jar;C:\bea\jdk130\jre\lib\i18n.jar;C:\bea\jdk130\jre\lib\sunrsasign.jar;C:\bea\jdk130\jre\classes;.;C:\bea\wlserver6.0\lib\weblogic_sp.jar;C:\bea\wlserver6.0\lib\weblogic.jar;C:\bea\wlserver6.0\lib\jce1_2_1.jar;C:\bea\wlserver6.0\lib\sunjce_provider.jar;C:\bea\wlserver6.0\lib\US_export_poli
              c
              >y.jar;C:\bea\wlserver6.0\lib\local_policy.jar;C:\bea\wlserver6.0\config\mydomain\applications\DefaultWebApp\WEB-INF\lib;;null,
              >> -d, C:\bea\testDir, C:\bea\testDir\jsp_servlet\_vgn\_portal\_system\_title.java])
              >> at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvoker.java:585)
              >> at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:354)
              >>
              >> Thanks in advance for the help.
              >>
              >>
              >
              >--
              >Michael Young
              >Developer Relations Engineer
              >BEA Support
              >
              >
              

              Hi Mike,
              Thanks for the response.
              I am getting this error
              C:\bea\testDir\jsp_servlet\_vgn\_portal\_system\_site\_edit.java:7: package jsp_servlet._vgn._portal._system
              clashes with class of same name
              Full compiler error(s): C:\bea\testDir\jsp_servlet\_vgn\_portal\_system\_site\_edit.java:7:
              package jsp_servlet._vgn._portal._system clashes with class of same name package
              jsp_servlet._vgn._portal._system._site; ^ 1 error
              This is the error on the screen and the messages I posted are from the weblogic.log
              Let me know if you need more info. Also, i found some suggestion somewhere that
              I should install rolling patch 2, bu i searched the downloads and did not find
              anything called Rolling Patch 2.
              Varun
              (No more information available, probably caused by another error) Michael Young
              <[email protected]> wrote:
              >Hi.
              >
              >Can you post the complete error? I don't see anything about class name
              >clashes in the exception you posted below.
              >
              >Cheers,
              >Michael
              >
              >Varun Garg wrote:
              >
              >> I am getting a "clashes with class of same name" error with some of
              >my jsp pages
              >> on weblogic 6.0 sp2. I have tried deleting my temporary jsp file, i
              >have tried
              >> using a working directory for the jsp using weblogic.xml.
              >>
              >> This happens for few files and not all of them
              >>
              >> java.io.IOException: Compiler failed executable.exec(java.lang.String[javac,
              >-classpath,
              >> C:\bea\wlserver6.0\config\mydomain\applications\DefaultWebApp_myserver;C:\bea\wlserver6.0\.\config\mydomain\applications\DefaultWebApp_myserver\WEB-INF\lib\ASTab.jar;C:\bea\testDir;C:\bea\jdk130\jre\lib\rt.jar;C:\bea\jdk130\jre\lib\i18n.jar;C:\bea\jdk130\jre\lib\sunrsasign.jar;C:\bea\jdk130\jre\classes;.;C:\bea\wlserver6.0\lib\weblogic_sp.jar;C:\bea\wlserver6.0\lib\weblogic.jar;C:\bea\wlserver6.0\lib\jce1_2_1.jar;C:\bea\wlserver6.0\lib\sunjce_provider.jar;C:\bea\wlserver6.0\lib\US_export_poli
              c
              >y.jar;C:\bea\wlserver6.0\lib\local_policy.jar;C:\bea\wlserver6.0\config\mydomain\applications\DefaultWebApp\WEB-INF\lib;;null,
              >> -d, C:\bea\testDir, C:\bea\testDir\jsp_servlet\_vgn\_portal\_system\_title.java])
              >> at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvoker.java:585)
              >> at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:354)
              >>
              >> Thanks in advance for the help.
              >>
              >>
              >
              >--
              >Michael Young
              >Developer Relations Engineer
              >BEA Support
              >
              >
              

  • Why do we need private static method or member class

    Dear java gurus,
    I have a question about the use of private and static key words together in a method or inner class.
    If we want to hide the method, private is enough. a private static method is sure not intended to be called outside the class. So the only usage I could see is that this private static method is to be called by another static method. For inner class, I see the definition of Entry inner class in java.util.Hashtable, it is static private. I don't know why not just define it as private. Could the static key word do anything better.
    Could anybody help me to clear this.
    Thanks,

    What don't you get? Private does one thing, andstatic does >something completely different.
    If you want to listen to music, installing an airconditioner doesn't help>
    Hi, if the private keyword is the airconditioner, do
    you think you could get music from the static keyword
    (it acts as the CD player) in the following codes:You're making no sense and you're trying to stretch the analogy too far.
    Private does one thing. If you want that thing, use private.
    Static does something completely different and unrelated. If you want that thing, use static.
    If you want both things, use private static.
    What do you not understand? How can you claim that you understand that they are different, and then ask, "Why do we need static if we have private"? That question makes no sense if you actually do understand that they're different.

  • Error creating instance of class from same package

    When I try to create an instance of a class that is in the same package, my IDE indicates that the constructor can not be found. Can anyone tell me what is wrong? Thanks. Below are the codes for both classes:
    package com.practice;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    public class WebProject extends Applet{
         public void init(){
                    // The following line is where the IDE indicates there is an error
              UserInterface gui = new UserInterface();
         } // end init()
         public void start(){
         } // end start()
         public void stop(){
         } // end stop()
         public void destroy(){
         } // end destory()
    } // end class
    package com.practice;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    public class UserInterface extends Applet{
         JPanel menuPanel = new JPanel();
         JPanel contentPanel = new JPanel();
         JPanel savePanel = new JPanel();
         ImageIcon saveIcon = new ImageIcon("workspace/images/toolbarButtongraphics/general/Save24");
         JButton saveButton = new JButton("Save", saveIcon);
         public UserInterface(){
              savePanel.add(saveButton);
              setLayout(new BorderLayout());
              add(menuPanel, BorderLayout.NORTH);
              add(contentPanel, BorderLayout.CENTER);
              add(savePanel, BorderLayout.SOUTH);
    } // end UserInterface class

    Thanks for the explanation and example. At first, I didn't understand what you were getting at, but after reading "Using Top-Level Containers" and "How to Use Root Panes" java tutorials it made much more sense. Unfortunately, the books I've read up to this point, did not cover those topics at all. The books simply stated that the first step in creating a Swing gui was to extend the JFrame, or JApplet, or etc.
    Unfortunately, my original problem persists. I continue to get compile-time errors such as:
    TestUserInterface.java:5: cannot find symbol
    symbol: class UserInterface
    location: class projects.web.TestUserInterface
                          UserInterface ui = new UserInterface(); Anyone know why?
    Both the classes are in the same named packaged. Below is my code:
    package projects.web;
    import java.awt.*;
    import javax.swing.*;
    public class UserInterface extends JFrame{
         JPanel menuPanel = new JPanel();
         JPanel contentPanel = new JPanel();
         JPanel selectionPanel = new JPanel();
         JButton save = new JButton("Save");
         JButton addFiles = new JButton("Add");
         public UserInterface(){
         super("File Upload");
         setSize(500, 500);
         menuPanel.add(addFiles);
         selectionPanel.add(save);
         setLayout(new BorderLayout());
         add(menuPanel, BorderLayout.NORTH);
         add(contentPanel, BorderLayout.CENTER);
         add(selectionPanel, BorderLayout.SOUTH);
         } // end constructor
    } // end UserInterface class
    package projects.web;
    public class TestUserInterface{
         public static void main(String[] args){
              UserInterface ui = new UserInterface();
    } // end TestUserInterface class

  • How to convert the class in the one package to same class in the other pack

    How to convert the class in the one package to same class in the other package
    example:
    BeanDTO.java
    package cho3.hello.bean;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    BeanDTO.java in other package
    package ch03.hello;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    My converter lass lokks like
    public class BeanUtilTest {
         public static void main(String[] args) {
              try
                   ch03.hello.BeanDTO bean=new ch03.hello.BeanDTO();
              bean.setAge(10);
              bean.setName("mahesh");
              cho3.hello.bean.BeanDTO beanDto=new cho3.hello.bean.BeanDTO();
              ClassConverter classconv=new ClassConverter();
              //classconv.
              System.out.println("hi "+beanDto.getClass().toString());
              System.out.println("hi helli "+bean.toString()+" "+bean.getAge()+" "+bean.getName()+" "+bean.getClass());
              Object b=classconv.convert(beanDto.getClass(),(Object)bean);
              System.out.println(b.toString());
              beanDto= (cho3.hello.bean.BeanDTO)b;
              System.out.println(" "+beanDto.getAge()+" "+beanDto.getName() );
              }catch(Exception e)
                   e.printStackTrace();
    But its giving class cast exception. Please help on this..

    Do you mean "two different layers" as in separate JVMs or "two different layers" as in functional areas running within the same JVM.
    In either case, if the first class is actually semantically and functionally the same as the second (and they are always intended to be the same) then import and and use the first class in place of the second. That's beyond any question of how to get the data of the first into the second if and when you need to.
    Once you make the breakthrough and use one class instead of two I'd guess that almost solves your problem. But if you want to describe your architecture a little that would help others pin down want you're trying to do.

  • Static imports in 1.5

    same static variable and same static method exists in two diffrent classes, while importing these two in my own implementation class follwing different output is coming why? Using j2se version1.5
    while using variable imports like
    import static package.Class1.variable1;
    import static package.Class2.variable1;
    //giving compilation errros
    while using method imports like
    import static package.Class1.method1;
    import static package.Class2.method1;
    //it is not giving any compilation error.
    Can anyone explain?

    >
    ah ok, when i wrote "Clearly" above i was assuming
    that the spec. when it does arrive (or when i can find
    it..) will disallow static imports of same signature
    methods (or possibly even just same named methods?) -
    and clearly any contravention of the spec should be
    reported to the userIf the spec says is should do something then it should do that.
    >
    on the other hand, the more the compiler can do the
    better since its a single point used by lots of
    people, so any small extra only has to be done once
    and is multiplied in the payoff - any individual
    trivial error message or warning might be
    questionable, but if lots are done then it saves time
    I doubt that a lot of people are going to be attempting to apply static imports to the same named item.
    not completely the same things, but i like the jikes
    feature where it says something like "it look like
    you're trying to invoke <SOME API METHOD> - this
    doesn't exist but a similar method does with
    signature: ... "
    I suspect that happens and is going to continue to happen far more frequently than duplicate static imports.
    And of course a compiler can add additional things like that. But that is rather different than suggesting that it is required.
    when a case is left in the grey area then at the very
    least a dozen developers will come across it and
    because of the lack of some text saying ERROR will
    start to question themselves - i don't see this as
    pandering to the developers laziness
    And yet none of the compilers warn against the "i = i++" construct.
    i've not verified this, and also the lang. spec does
    not seem to have been updated for 1.5???
    it sounds like the compiler should just complain in
    both cases?Yes but given that neither has been used I suspect
    that it will complain once they are used. If it
    doesn't then that is a bug.hm, a similar piece of code
    import java.util.List; import java.awt.List;
    complains immediately if you try to compile it - i guess this
    isn't that important but i like the
    complain-loudly-and-early approach - i think they also
    possibly made unused imports or duplicate imports
    errors or warnings for 1.5?Could be. However, the spec itself drags significantly behind the additional material. For example note that the 'current' spec doesn't have assert. So tracking down what should really be in the spec can be somewhat complicated.
    Note also that I haven't really seen the OP clarify that they expect an error for both cases rather than that they expect that no error at all should show up (because they really want to use both.) And although the first is nice the second is clearly wrong. Hopefully that point is clear.

  • Static Import question

    It is a very easy (down to earth) question.
    Are static imports of methods having the same name as
    Object methods forbidden?public class StaticUse1 { 
      public static boolean equals(StaticUse1 su1,StaticUse1 su2) {
        return true;
      public static boolean equal(StaticUse1 su1,StaticUse1 su2) {
        return false;
    }An import somewhere else:import static apackage.StaticUse1.*;
    public class Test {
      public static void main(String[] args) {
        //System.out.println(equals(new StaticUse1(),new StaticUse1()));  // error
        System.out.println(equal(new StaticUse1(),new StaticUse1()));
    }Compiler complains about ... equals(java.lang.Object) ...

    Such static imports are allowed, but they won't work because of the scoping rules of the language. The equals(Object) for the current class always shadow such methods from the static import.

  • Static import bug?

    Hey just discovered something new...does this sound like a bug to you guys?
    I have a class with a static method called, say, omgMethod()
    and I have another class with a method (not static) with the same name (omgMethod) but different signature.
    now when I try to use import static classA.omgMethod in the second class, it generates a compiler error:
    cannot find symbol method omgMethod( etc...)
    any thoughts? i'm thinking about adding it to the bug report.
    -Cuppo

    I'm not so sure about that. I have never used static import so I checked out Sun's tutorial which is here:
    http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html
    It talks about importing "members" and says you can import "members" individually. And (I had to look this up too in the JLS), "members" means classes, interfaces, fields, and methods.
    So that says to me that you can indeed import a static method from another class, and then use it without qualification. Yeah, I'm surprised too. But you're just importing the method's name, not its signature. So if that name conflicts with a name of a method in your class, then I don't know what is supposed to happen. I looked through the JLS a bit and section 6.5.7.1 says
    "The Identifier must name at least one visible (�6.3.1) method that is in scope at the point where the Identifier appear or a method imported by a single-static-import declaration (�7.5.3) or static-import-on-demand declaration (�7.5.4) within the compilation unit within which the Identifier appears.
    See �15.12 for further discussion of the interpretation of simple method names in method invocation expressions."
    Possibly section 15.12 discusses conflict resolution in this case. But I will let you carry on from there.

  • Axis Fault: JavaProvider can not access a member of class Hello with mod.

    Hi,
    I am getting the following Axis Fault with content
    Exception in thread "main" AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.lang.IllegalAccessException: Class org.apache.axis.providers.java.JavaProvider can not access a member of class Hello with modifiers ""
    faultActor:
    faultNode:
    faultDetail:
         {http://xml.apache.org/axis/}hostname:SNR143052
    java.lang.IllegalAccessException: Class org.apache.axis.providers.java.JavaProvider can not access a member of class Hello with modifiers ""
         at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
         at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
         at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(XMLNSDocumentScannerImpl.java:719)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
         at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
         at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
         at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
         at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
         at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
         at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
         at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
         at org.apache.axis.client.Call.invoke(Call.java:2767)
         at org.apache.axis.client.Call.invoke(Call.java:2443)
         at org.apache.axis.client.Call.invoke(Call.java:2366)
         at org.apache.axis.client.Call.invoke(Call.java:1812)
    The client code for the webservice using instant deployment is
    import java.net.URL;
    import javax.xml.rpc.ParameterMode;
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.encoding.XMLType;
    import org.apache.axis.utils.Options;
    public class ClientHello {
         public ClientHello(){
         public static void main(String[] args) throws Exception{
              Options options = new Options(args);
              String endpoint = "http://localhost:" + options.getPort()+"/WebServices/Hello.jws";
              args = options.getRemainingArgs();
              Service services = new Service();
              Call call = (Call) services.createCall();
              call.setTargetEndpointAddress(new URL(endpoint));
              call.setOperationName(args[0]);
              call.addParameter("op1",XMLType.XSD_STRING,ParameterMode.IN);
              call.setReturnType(XMLType.XSD_STRING);
              System.out.print(args[1]);
              String s = new String(args[1]);
              String result = (String) call.invoke(new Object[]{s});
              System.out.println(result);
    The hello.jws is as follows
    class Hello {
         public String hi(String message){
              return "Hello "+ message;
    I am not sure why the message is substituted with "" instead of the parameter i have sent in args[1].
    Please help me out in this regard.
    Thanks,
    winkidzz

    Thanks swatdba.
    Any idea on how to proceed with implementing Webservices using Websphere MQ?

  • Reflection problem: can not access a member of class java.lang.IllegalAcces

    package org.struts.ets.utility;
    import java.lang.reflect.Constructor;
    import java.lang.reflect.Field;
    import java.lang.reflect.InvocationTargetException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import org.struts.bean.FieldTrouble;
    import org.struts.bean.GenericDAOBean;
    public class DynamicObjectCreation
         public static void main(String... args)
              FieldTrouble ft = new FieldTrouble();
              try
                   Class<?> c = ft.getClass();
                   //Class<?> c = FieldTrouble.class;
                   /*Class<?> c = null;
                   try
                        c = Class.forName("org.struts.bean.FieldTrouble");
                   } catch (ClassNotFoundException e)
                        e.printStackTrace();
                   Field f = c.getDeclaredField("var1");
                   //f.setInt(ft, 42); // IllegalArgumentException
                   f.set(ft, new String("A"));
                   System.out.println(ft.getVar1());
                   // production code should handle these exceptions more gracefully
              } catch (NoSuchFieldException x)
                   x.printStackTrace();
              } catch (IllegalAccessException x)
                   x.printStackTrace();
    }// If I put FieldTrouble.java in any other package than the current package I am running this code from. I get the following error:
    java.lang.IllegalAccessException: Class org.struts.ets.utility.DynamicObjectCreation can not access a member of class org.struts.bean.FieldTrouble with modifiers ""
         at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
         at java.lang.reflect.Field.doSecurityCheck(Unknown Source)
         at java.lang.reflect.Field.getFieldAccessor(Unknown Source)
         at java.lang.reflect.Field.set(Unknown Source)
         at org.struts.ets.utility.DynamicObjectCreation.main(DynamicObjectCreation.java:35)
    I tried all possible ways of creating class as:
    Class<?> c = ft.getClass(); OR
    Class<?> c = FieldTrouble.class; OR
                   /*Class<?> c = null;
                   try
                        c = Class.forName("org.struts.bean.FieldTrouble");
                   } catch (ClassNotFoundException e)
                        e.printStackTrace();
    Edited by: ..-__Kris__-.. on Feb 21, 2008 10:26 AM
    Edited by: ..-__Kris__-.. on Feb 21, 2008 10:26 AM

    Any hidden performance or memory issue here?
    Let us consider an object:
    public class SomeObject
         private String fieldA;
         private String fieldB;
         private String fieldC;
         private String fieldD;
         private String fieldE;
         //... say 50 declared fields....
         public SomeObject()
         public SomeObject(String fieldA, String fieldB)
              this.fieldA = fieldA;
              this.fieldB = fieldB;
    // getters and setters..     
    }When I create an object using the constructor with only two fields initialized such as the following code above, and look at what is happening to other fields as shown in the code below, I see that they are also AVAILABLE, now this is important, but they are set to null. What I wanted to know was, if I created an object with many fields, as many as 50 (getDeclaredFields = 50), and used a constructor with only two input fields to initialize an object, I still have 48 other fields available but set as NULL's. When I create more than 100,000 of these objects in a list and send to a .jsp page, I am unable to understand if this has more memory load than when you use a list of another object which has actually has only two declared fields in it. Each of this new object will have only two declared fields, when I say getDeclaredFields() it would return 2.
    This is where I am unable to figure out if this has anything to do with performance or memory, rather, what is the difference between the many possible ways you can initialize an object when there are too many fields which you probably won't use? Either create a new constructor with only two input arguments OR a generic constructor with all fields as input arguments but all those fields which you won't use assigned NULL's OR create another new object with only two declared fields
    SomeObject someObj = new SomeObject("abcd","cdef");
              Field[] fields = someObj.getClass().getDeclaredFields();
              System.out.println("Number of available fields: " + fields.length);
              for(int i = 0 ; i < fields.length ; i++)
                   try
                        fields.setAccessible(true);
                        System.out.println("Field " + i + ", with value: " + fields[i].get(someObj));
                        fields[i].get(someObj);
                   } catch (IllegalArgumentException e)
                        e.printStackTrace();
                   } catch (IllegalAccessException e)
                        e.printStackTrace();
              }Edited by: ..-__Kris__-.. on Mar 23, 2008 5:04 PM
    Edited by: ..-__Kris__-.. on Mar 23, 2008 5:05 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Importing a .class file into my package?

    Hi. I'm making a java program but I need to use an external .class file to get variables and use methods from. Is it possible to "import" a class file into my package to be able to do so?
    Thanks

    Basically, for our last project we created a class
    that held the information about a year: how many days
    were in a month, how many months were in a year, etc.
    etc. For this project, we'll be having to use that
    same class to make a GUI calendar. Our teacher
    provided a class which he compiled for us to use in
    our projects incase our previous class had some flaws
    in it, which mine did. Unfortunately, it's in .class
    format and I don't know how to use it in my package!That's going to be a problem then. I would assume that it is going to have an API like your old one did. Same name and same methods etc. So do you know what the name and method signatures of your class were supposed to be?

  • Static import from SE5 (Ex 16 on p. 91 in Thinking in Java Edn 4 by Eckel)

    The following line of code is underlined:
    import static net.mindview.util.Print.*;with this error displayed:
    static import declarations are not supported in -source 1.4
    (try -source 1.5 to enable static import declarations).
    My Path variable contains these:
    C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\Java\jre1.6.0\bin;D:\java\TIJ4\code
    D:\java\TIJ4\code is the root folder for net.mindview.util.Print.
    JRE1.6 and JDK1.6 are installed.
    I also have:
    i.e. a dot, in my CLASSPATH variable.
    This is from the 4th edn of Thinking in Java by Bruce Eckel. If you are or have been through this stuff I would really appreciate it if we could meet on Skype every now and then to talk about issues like the one described above.
    Thanks for your help,
    b

    Now same code is underlined:
    import static net.mindview.util.Print.*;but with this error message:
    package net.mindview.util does not exist
    However it is mapped like this:
    D:\java\TIJ4\code\net\mindview etc..
    So, I have put this in to the Path variable:
    D:\java\TIJ4\code because it is the root folder of net.mindview.util.
    Is there something else I should do? Is is ok to have a non C directory in the Path variable?
    Thanks for any help,
    B

  • Cannot static import in JSP (WebLogic 10.3)

    I am facing a problem with the use of 'static import' in JSP. This is on WebLogic 10.3. Please help/advise.
    Running weblogic.jspc results in the following error:+
    $ java weblogic.jspc -verboseJspc -keepgenerated -d /tmp/jsp WEB-INF/jspf/fragment.jspf
    \[jspc\] Overriding descriptor option 'keepgenerated' with value specified on command-line 'true'
    \[jspc\] Compiling /WEB-INF/jspf/fragment.jspf
    jspc failed with errors :weblogic.servlet.jsp.CompilationException: fragment.jspf:6:17: Syntax error on token "static", Identifier expected after this token
    <%@page import="static java.util.Collections.EMPTY_LIST" %>
    ^-------------------------------------^
    fragment.jspf:6:17: The import java.util.Collections.EMPTY_LIST cannot be resolved
    <%@page import="static java.util.Collections.EMPTY_LIST" %>
    ^-------------------------------------^
    The generated Java file is not correct; the static import is split into multiple imports+
    $ head /tmp/jsp/jsp_servlet/_web_45_inf/_jspf/__fragment_jspf.java
    package jsp_servlet._web_45_inf._jspf;
    import java.lang.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    import static;
    import java.util.Collections.EMPTY_LIST;
    public final class __fragment_jspf extends weblogic.servlet.jsp.JspBase implements weblogic.servlet.jsp.StaleIndicator {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I'm not sure that JSPC supports static imports, I would open a support case to get clarification.

  • Can we call a static method without mentioning the class name

    public class Stuff {
         public static final int MY_CONSTANT = 5;
         public static int doStuff(int x){ return (x++)*x;}
    import xcom.Stuff.*;
    import java.lang.System.out;
    class User {
       public static void main(String[] args){
       new User().go();
       void go(){out.println(doStuff(MY_CONSTANT));}
    }Will the above code compile?
    can be call a static method without mentioning the class name?

    Yes, why do it simply?
    pksingh79 wrote:
    call a static method without mentioning the class name?For a given value of   "without mentioning the class name".
        public static Object invokeStaticMethod(String className, String methodName, Object[] args) throws Exception {
            Class<?>[] types = new Class<?>[args.length];
            for(int i=0;i<args.length;++i) types[i] = args==null?Object.class:args[i].getClass();
    return Class.forName(className).getDeclaredMethod(methodName,types).invoke(null,args);

Maybe you are looking for

  • Java null pointer exception while getting a segment DFF handle

    Hi, my requirement is to make a field mandatory based upon a dff segment value (Y/N). i override PFR since segment is a poplist on the page (and poplists don't fire any event) i searched in the "view source" of the page and found that segment id is A

  • Pattern matching for range of numbers

    I am facing problem in using a pattern like [200-300] to match any number in the range 200 and 300 inclusive. I wrote following code: public class RangeTest {      public static void main(String[] args) {           String pat = "[100-200]";          

  • Intrastat - missing lines (invoices based on interco PO)

    All, I have an issue with the intrastat declaration (trx VI98 u2013 program RVIVST00). Some lines are missing, and when I debug I see that the program skips the line because the sales document where the invoice is based on is of document category V (

  • Spring / Toplink Transaction / Commit Issue

    Hi, Im working on a spring / toplink integration on my project. The problem Im facing has to do with transaction / commits Im using a TransactionProxyFactoryBean to encapsulate a BusinessProcess responsible for creating a new Company Instance and its

  • Need Assistance PLEASE

    I just purchased Studio 8 and I would like to know if I need Coldfusion MX7 or does one of the programs contain Coldfusion or Coldfusion behavior?