Announcement Announcement Module
Collapse
No announcement yet.
HttpRemote exception:I can not get the data from server! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HttpRemote exception:I can not get the data from server!

    when i run client application via webstart,i found the data can not got from server.The configuration files and some codes as follows:

    clientContext.xml:
    Code:
    <bean id="depotSubFrameManager" 
    class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"><property name="serviceUrl"><value>http&#58;//$&#123;serverName&#125;&#58;$&#123;httpPort$&#123;contextPath&#125;/remoting/DepotSubFrameManager</value></property>
    <property name="serviceInterface">
    <value>com.jctx.trms.hibernate.bussiness.DepotSubFrameManager</value></property>
    </bean>
    remoting-servlet.xml:
    Code:
    <bean name="/DepotSubFrameManager"
    class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
    <property name="service">
    <ref bean="depotSubFrameManager"/>
    </property>
    <property name="serviceInterface">
    <value>com.jctx.trms.hibernate.bussiness.DepotSubFrameManager</value></property>
    </bean>
    applicationContext.xml:
    Code:
    <bean id="depotSubFrameDAO" class="com.jctx.trms.hibernate.DAO.DepotSubFrameDAOImpl">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
        </bean>
        <bean id="depotSubFrameManager" parent="txProxyTemplate">
            <property name="target">
                <bean class="com.jctx.trms.hibernate.bussiness.DepotSubFrameManagerImpl">
                    <property name="depotSubFrameDAO"><ref bean="depotSubFrameDAO"/></property>         
                </bean>
            </property>
        </bean>
    get the bean:
    Code:
    public static DepotSubFrameManager getDepotSubFrameManager&#40;&#41; &#123;
    return &#40;DepotSubFrameManager&#41; &#40;getContext&#40;&#41;.getBean&#40;"depotSubFrameManager"&#41;&#41;;
    &#125;
    call the service:
    Code:
    DepotSubFrameManager depotsubframem = &#40;DepotSubFrameManager&#41; GlobalApplicationContext.getDepotSubFrameManager&#40;&#41;;
    System.out.println&#40;"the value of depotsubframem is " + depotsubframem&#41;;
    List lts = depotsubframem.findAll&#40;&#41;; &#91;color=red&#93;//&#40;1&#41;&#91;/color&#93;
        Iterator its = lts.iterator&#40;&#41;;
    my dao is:
    Code:
    public List findAll&#40;&#41;&#123;
            List list = getHibernateTemplate&#40;&#41;.find&#40;"from com.jctx.trms.hibernate.persistence.DepotSubFrame"&#41;;
    System.out.println&#40;"the length of size is " + list.size&#40;&#41;&#41;;    &#91;color=red&#93;  //&#40;2&#41;&#91;/color&#93;             return list;
        &#125;
    in server,the console print the size of list is 6,but in client,the program run to the row which marked (1) throw the java.lang.NullPointerException,and in the console of client ,the value of depotsubframem is

    Code:
    HTTP invoker proxy for service URL &#91;http&#58;//localhost&#58;8080/trms/remoting/DepotSubFrameManager&#93;
    the exception of client console is:

    Code:
    java.lang.NullPointerException
    	at com.jctx.trms.hibernate.persistence.BaseObject.hashCodeReflectionAppend&#40;BaseObject.java&#58;115&#41;
    	at com.jctx.trms.hibernate.persistence.BaseObject.hashCode&#40;BaseObject.java&#58;98&#41;
    	at org.apache.commons.lang.builder.HashCodeBuilder.append&#40;HashCodeBuilder.java&#58;392&#41;
    	at com.jctx.trms.hibernate.persistence.BaseObject.hashCodeReflectionAppend&#40;BaseObject.java&#58;118&#41;
    	at com.jctx.trms.hibernate.persistence.BaseObject.hashCode&#40;BaseObject.java&#58;98&#41;
    	at java.util.HashMap.hash&#40;HashMap.java&#58;261&#41;
    	at java.util.HashMap.putForCreate&#40;HashMap.java&#58;404&#41;
    	at java.util.HashMap.readObject&#40;HashMap.java&#58;1007&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at java.io.ObjectStreamClass.invokeReadObject&#40;ObjectStreamClass.java&#58;838&#41;
    	at java.io.ObjectInputStream.readSerialData&#40;ObjectInputStream.java&#58;1746&#41;
    	at java.io.ObjectInputStream.readOrdinaryObject&#40;ObjectInputStream.java&#58;1646&#41;
    	at java.io.ObjectInputStream.readObject0&#40;ObjectInputStream.java&#58;1274&#41;
    	at java.io.ObjectInputStream.defaultReadFields&#40;ObjectInputStream.java&#58;1845&#41;
    	at java.io.ObjectInputStream.readSerialData&#40;ObjectInputStream.java&#58;1769&#41;
    	at java.io.ObjectInputStream.readOrdinaryObject&#40;ObjectInputStream.java&#58;1646&#41;
    	at java.io.ObjectInputStream.readObject0&#40;ObjectInputStream.java&#58;1274&#41;
    	at java.io.ObjectInputStream.defaultReadFields&#40;ObjectInputStream.java&#58;1845&#41;
    	at java.io.ObjectInputStream.readSerialData&#40;ObjectInputStream.java&#58;1769&#41;
    	at java.io.ObjectInputStream.readOrdinaryObject&#40;ObjectInputStream.java&#58;1646&#41;
    	at java.io.ObjectInputStream.readObject0&#40;ObjectInputStream.java&#58;1274&#41;
    	at java.io.ObjectInputStream.defaultReadFields&#40;ObjectInputStream.java&#58;1845&#41;
    	at java.io.ObjectInputStream.readSerialData&#40;ObjectInputStream.java&#58;1769&#41;
    	at java.io.ObjectInputStream.readOrdinaryObject&#40;ObjectInputStream.java&#58;1646&#41;
    	at java.io.ObjectInputStream.readObject0&#40;ObjectInputStream.java&#58;1274&#41;
    	at java.io.ObjectInputStream.defaultReadFields&#40;ObjectInputStream.java&#58;1845&#41;
    	at java.io.ObjectInputStream.readSerialData&#40;ObjectInputStream.java&#58;1769&#41;
    	at java.io.ObjectInputStream.readOrdinaryObject&#40;ObjectInputStream.java&#58;1646&#41;
    	at java.io.ObjectInputStream.readObject0&#40;ObjectInputStream.java&#58;1274&#41;
    	at java.io.ObjectInputStream.readObject&#40;ObjectInputStream.java&#58;324&#41;
    	at java.util.ArrayList.readObject&#40;ArrayList.java&#58;547&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at java.io.ObjectStreamClass.invokeReadObject&#40;ObjectStreamClass.java&#58;838&#41;
    	at java.io.ObjectInputStream.readSerialData&#40;ObjectInputStream.java&#58;1746&#41;
    	at java.io.ObjectInputStream.readOrdinaryObject&#40;ObjectInputStream.java&#58;1646&#41;
    	at java.io.ObjectInputStream.readObject0&#40;ObjectInputStream.java&#58;1274&#41;
    	at java.io.ObjectInputStream.defaultReadFields&#40;ObjectInputStream.java&#58;1845&#41;
    	at java.io.ObjectInputStream.readSerialData&#40;ObjectInputStream.java&#58;1769&#41;
    	at java.io.ObjectInputStream.readOrdinaryObject&#40;ObjectInputStream.java&#58;1646&#41;
    	at java.io.ObjectInputStream.readObject0&#40;ObjectInputStream.java&#58;1274&#41;
    	at java.io.ObjectInputStream.readObject&#40;ObjectInputStream.java&#58;324&#41;
    	at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.doReadRemoteInvocationResult&#40;AbstractHttpInvokerRequestExecutor.java&#58;233&#41;
    	at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.readRemoteInvocationResult&#40;AbstractHttpInvokerRequestExecutor.java&#58;181&#41;
    	at org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor.doExecuteRequest&#40;SimpleHttpInvokerRequestExecutor.java&#58;55&#41;
    	at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest&#40;AbstractHttpInvokerRequestExecutor.java&#58;68&#41;
    	at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest&#40;HttpInvokerClientInterceptor.java&#58;138&#41;
    	at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke&#40;HttpInvokerClientInterceptor.java&#58;112&#41;
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed&#40;ReflectiveMethodInvocation.java&#58;144&#41;
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke&#40;JdkDynamicAopProxy.java&#58;174&#41;
    	at $Proxy39.findAll&#40;Unknown Source&#41;
    	at com.jctx.trms.hibernate.bussiness.IniTree.getTreeList&#40;IniTree.java&#58;70&#41;
    	at com.jctx.trms.tree.TreeBean.<init>&#40;TreeBean.java&#58;19&#41;
    	at com.jctx.trms.tree.TreeBean.getInstance&#40;TreeBean.java&#58;29&#41;
    	at com.jctx.trms.tree.MainTree$JCTreeContentProvider.getElements&#40;MainTree.java&#58;241&#41;
    	at org.eclipse.jface.viewers.StructuredViewer.getRawChildren&#40;StructuredViewer.java&#58;532&#41;
    	at org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren&#40;AbstractTreeViewer.java&#58;704&#41;
    	at org.eclipse.jface.viewers.StructuredViewer.getFilteredChildren&#40;StructuredViewer.java&#58;477&#41;
    	at org.eclipse.jface.viewers.StructuredViewer.getSortedChildren&#40;StructuredViewer.java&#58;585&#41;
    	at org.eclipse.jface.viewers.AbstractTreeViewer$1.run&#40;AbstractTreeViewer.java&#58;359&#41;
    	at org.eclipse.swt.custom.BusyIndicator.showWhile&#40;BusyIndicator.java&#58;69&#41;
    	at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren&#40;AbstractTreeViewer.java&#58;342&#41;
    	at org.eclipse.jface.viewers.AbstractTreeViewer$5.run&#40;AbstractTreeViewer.java&#58;787&#41;
    	at org.eclipse.jface.viewers.StructuredViewer.preservingSelection&#40;StructuredViewer.java&#58;862&#41;
    	at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged&#40;AbstractTreeViewer.java&#58;777&#41;
    	at org.eclipse.jface.viewers.ContentViewer.setInput&#40;ContentViewer.java&#58;238&#41;
    	at org.eclipse.jface.viewers.StructuredViewer.setInput&#40;StructuredViewer.java&#58;1059&#41;
    	at com.jctx.trms.tree.MainTree.createTreeViewer&#40;MainTree.java&#58;100&#41;
    	at com.jctx.trms.views.SearchView.createPartControl&#40;SearchView.java&#58;15&#41;
    	at org.eclipse.ui.internal.PartPane$2.run&#40;PartPane.java&#58;137&#41;
    	at org.eclipse.core.internal.runtime.InternalPlatform.run&#40;InternalPlatform.java&#58;616&#41;
    	at org.eclipse.core.runtime.Platform.run&#40;Platform.java&#58;747&#41;
    	at org.eclipse.ui.internal.PartPane.createChildControl&#40;PartPane.java&#58;133&#41;
    	at org.eclipse.ui.internal.ViewPane.createChildControl&#40;ViewPane.java&#58;135&#41;
    	at org.eclipse.ui.internal.ViewFactory$1.run&#40;ViewFactory.java&#58;351&#41;
    	at org.eclipse.core.internal.runtime.InternalPlatform.run&#40;InternalPlatform.java&#58;616&#41;
    	at org.eclipse.core.runtime.Platform.run&#40;Platform.java&#58;747&#41;
    	at org.eclipse.ui.internal.ViewFactory.busyRestoreView&#40;ViewFactory.java&#58;273&#41;
    	at org.eclipse.ui.internal.ViewFactory$2.run&#40;ViewFactory.java&#58;530&#41;
    	at org.eclipse.swt.custom.BusyIndicator.showWhile&#40;BusyIndicator.java&#58;69&#41;
    	at org.eclipse.ui.internal.ViewFactory.restoreView&#40;ViewFactory.java&#58;528&#41;
    	at org.eclipse.ui.internal.ViewFactory$ViewReference.getPart&#40;ViewFactory.java&#58;102&#41;
    	at org.eclipse.ui.internal.WorkbenchPage$1.propertyChange&#40;WorkbenchPage.java&#58;132&#41;
    	at org.eclipse.ui.internal.LayoutPart.setVisible&#40;LayoutPart.java&#58;268&#41;
    	at org.eclipse.ui.internal.PartPane.setVisible&#40;PartPane.java&#58;317&#41;
    	at org.eclipse.ui.internal.ViewPane.setVisible&#40;ViewPane.java&#58;568&#41;
    	at org.eclipse.ui.internal.presentations.PresentablePart.setVisible&#40;PresentablePart.java&#58;122&#41;
    	at org.eclipse.ui.internal.presentations.DefaultPartPresentation.selectPart&#40;DefaultPartPresentation.java&#58;1116&#41;
    	at org.eclipse.ui.internal.PartStack.refreshPresentationSelection&#40;PartStack.java&#58;946&#41;
    	at org.eclipse.ui.internal.PartStack.setSelection&#40;PartStack.java&#58;921&#41;
    	at org.eclipse.ui.internal.PartStack.showPart&#40;PartStack.java&#58;1020&#41;
    	at org.eclipse.ui.internal.PartStack.createControl&#40;PartStack.java&#58;383&#41;
    	at org.eclipse.ui.internal.PartStack.createControl&#40;PartStack.java&#58;367&#41;
    	at org.eclipse.ui.internal.PartSashContainer.createControl&#40;PartSashContainer.java&#58;432&#41;
    	at org.eclipse.ui.internal.PerspectiveHelper.activate&#40;PerspectiveHelper.java&#58;155&#41;
    	at org.eclipse.ui.internal.Perspective.onActivate&#40;Perspective.java&#58;732&#41;
    	at org.eclipse.ui.internal.WorkbenchPage.onActivate&#40;WorkbenchPage.java&#58;2063&#41;
    	at org.eclipse.ui.internal.WorkbenchWindow$4.run&#40;WorkbenchWindow.java&#58;1858&#41;
    	at org.eclipse.swt.custom.BusyIndicator.showWhile&#40;BusyIndicator.java&#58;69&#41;
    	at org.eclipse.ui.internal.WorkbenchWindow.setActivePage&#40;WorkbenchWindow.java&#58;1845&#41;
    	at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage&#40;WorkbenchWindow.java&#58;498&#41;
    	at org.eclipse.ui.internal.WorkbenchWindow$3.run&#40;WorkbenchWindow.java&#58;1076&#41;
    	at org.eclipse.swt.custom.BusyIndicator.showWhile&#40;BusyIndicator.java&#58;69&#41;
    	at org.eclipse.ui.internal.WorkbenchWindow.openPage&#40;WorkbenchWindow.java&#58;1073&#41;
    	at org.eclipse.ui.internal.Workbench.openFirstTimeWindow&#40;Workbench.java&#58;992&#41;
    	at org.eclipse.ui.internal.WorkbenchConfigurer.openFirstTimeWindow&#40;WorkbenchConfigurer.java&#58;174&#41;
    	at org.eclipse.ui.application.WorkbenchAdvisor.openWindows&#40;WorkbenchAdvisor.java&#58;658&#41;
    	at org.eclipse.ui.internal.Workbench.init&#40;Workbench.java&#58;819&#41;
    	at org.eclipse.ui.internal.Workbench.runUI&#40;Workbench.java&#58;1325&#41;
    	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench&#40;Workbench.java&#58;254&#41;
    	at org.eclipse.ui.PlatformUI.createAndRunWorkbench&#40;PlatformUI.java&#58;141&#41;
    	at com.jctx.trms.TrmsApplication.run&#40;TrmsApplication.java&#58;14&#41;
    	at org.eclipse.core.internal.runtime.PlatformActivator$1.run&#40;PlatformActivator.java&#58;335&#41;
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run&#40;EclipseStarter.java&#58;273&#41;
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run&#40;EclipseStarter.java&#58;129&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at java.lang.reflect.Method.invoke&#40;Method.java&#58;324&#41;
    	at org.eclipse.core.launcher.Main.basicRun&#40;Main.java&#58;185&#41;
    	at org.eclipse.core.launcher.Main.run&#40;Main.java&#58;704&#41;
    	at org.eclipse.core.launcher.Main.main&#40;Main.java&#58;688&#41;
    Can anyone please spot what I have done wrong, thanks very much.

    Jesse

  • #2
    Could you show me the hashCode implementation for BaseObject, as well as the hashCodeReflectionAppend implementation?

    thanx,
    Alef Arendsen

    Comment


    • #3
      The class is :
      Code:
      package com.jctx.trms.hibernate.persistence;
      
      import java.io.Serializable;
      import java.lang.reflect.AccessibleObject;
      import java.lang.reflect.Field;
      import java.lang.reflect.Modifier;
      import java.util.Collection;
      
      import org.apache.commons.lang.builder.EqualsBuilder;
      import org.apache.commons.lang.builder.HashCodeBuilder;
      import org.apache.commons.lang.builder.ToStringBuilder;
      import org.apache.commons.lang.builder.ToStringStyle;
      
      public class BaseObject implements Serializable &#123;
          public String toString&#40;&#41; &#123;
              return ToStringBuilder.reflectionToString&#40;this, ToStringStyle.MULTI_LINE_STYLE&#41;;
          &#125;
      
          public boolean equals&#40;Object o&#41; &#123;
              if &#40;this == o&#41; &#123;
                  return true;
              &#125;
              if &#40;o == null&#41; &#123;
                  return false;
              &#125;
              // Find the leaf class since there may be transients in the leaf
              // class or in classes between the leaf and root.
              // If we are not testing transients or a subclass has no ivars,
              // then a subclass can test equals to a superclass.
              Class lhsClass = getClass&#40;&#41;;
              Class rhsClass = o.getClass&#40;&#41;;
              Class testClass;
              if &#40;lhsClass.isInstance&#40;o&#41;&#41; &#123;
                  testClass = lhsClass;
                  if &#40;!rhsClass.isInstance&#40;this&#41;&#41; &#123;
                      // rhsClass is a subclass of lhsClass
                      testClass = rhsClass;
                  &#125;
              &#125;
              else if &#40;rhsClass.isInstance&#40;this&#41;&#41; &#123;
                  testClass = rhsClass;
                  if &#40;!lhsClass.isInstance&#40;o&#41;&#41; &#123;
                      // lhsClass is a subclass of rhsClass
                      testClass = lhsClass;
                  &#125;
              &#125;
              else &#123;
                  // The two classes are not related.
                  return false;
              &#125;
              EqualsBuilder equalsBuilder = new EqualsBuilder&#40;&#41;;
              try &#123;
                  equalsReflectionAppend&#40;o, testClass, equalsBuilder&#41;;
                  while &#40;testClass.getSuperclass&#40;&#41; != null
                          && !testClass.getSuperclass&#40;&#41;.equals&#40;Object.class&#41;&#41; &#123;
                      testClass = testClass.getSuperclass&#40;&#41;;
                      equalsReflectionAppend&#40;o, testClass, equalsBuilder&#41;;
                  &#125;
              &#125;
              catch &#40;IllegalArgumentException e&#41; &#123;
                  // In this case, we tried to test a subclass vs. a superclass and
                  // the subclass has ivars or the ivars are transient and
                  // we are testing transients.
                  // If a subclass has ivars that we are trying to test them, we get an
                  // exception and we know that the objects are not equal.
                  return false;
              &#125;
              return equalsBuilder.isEquals&#40;&#41;;
          &#125;
      
          private void equalsReflectionAppend&#40;Object rhs, Class clazz, EqualsBuilder builder&#41; &#123;
              Field&#91;&#93; fields = clazz.getDeclaredFields&#40;&#41;;
              AccessibleObject.setAccessible&#40;fields, true&#41;;
              for &#40;int i = 0; i < fields.length && builder.isEquals&#40;&#41;; i++&#41; &#123;
                  Field f = fields&#91;i&#93;;
                  if &#40;&#40;f.getName&#40;&#41;.indexOf&#40;'$'&#41; == -1&#41; && &#40;!Modifier.isTransient&#40;f.getModifiers&#40;&#41;&#41;&#41;
                          && &#40;!Modifier.isStatic&#40;f.getModifiers&#40;&#41;&#41;&#41;&#41; &#123;
                      try &#123;
                          if &#40;Collection.class.isAssignableFrom&#40;f.getType&#40;&#41;&#41;&#41; &#123;
                              builder.append&#40;f.get&#40;this&#41;.getClass&#40;&#41;, f.get&#40;rhs&#41;.getClass&#40;&#41;&#41;;
                          &#125;
                          else &#123;
                              builder.append&#40;f.get&#40;this&#41;, f.get&#40;rhs&#41;&#41;;
                          &#125;
                      &#125;
                      catch &#40;IllegalAccessException e&#41; &#123;
                          //this can't happen. Would get a Security exception instead
                          //throw a runtime exception in case the impossible happens.
                          throw new InternalError&#40;"Unexpected IllegalAccessException"&#41;;
                      &#125;
                  &#125;
              &#125;
          &#125;
      
          public int hashCode&#40;&#41; &#123;
              HashCodeBuilder builder = new HashCodeBuilder&#40;17, 37&#41;;
              Class clazz = getClass&#40;&#41;;
              hashCodeReflectionAppend&#40;clazz, builder&#41;;
              while &#40;clazz.getSuperclass&#40;&#41; != null && clazz.getSuperclass&#40;&#41;.equals&#40;Object.class&#41;&#41; &#123;
                  clazz = clazz.getSuperclass&#40;&#41;;
                  hashCodeReflectionAppend&#40;clazz, builder&#41;;
              &#125;
              return builder.toHashCode&#40;&#41;;
          &#125;
      
          private void hashCodeReflectionAppend&#40;Class clazz, HashCodeBuilder builder&#41; &#123;
              Field&#91;&#93; fields = clazz.getDeclaredFields&#40;&#41;;
              AccessibleObject.setAccessible&#40;fields, true&#41;;
              for &#40;int i = 0; i < fields.length; i++&#41; &#123;
                  Field f = fields&#91;i&#93;;
                  if &#40;&#40;f.getName&#40;&#41;.indexOf&#40;'$'&#41; == -1&#41; && &#40;!Modifier.isTransient&#40;f.getModifiers&#40;&#41;&#41;&#41;
                          && &#40;!Modifier.isStatic&#40;f.getModifiers&#40;&#41;&#41;&#41;&#41; &#123;
                      try &#123;
                          if &#40;Collection.class.isAssignableFrom&#40;f.getType&#40;&#41;&#41;&#41; &#123;
                              builder.append&#40;f.get&#40;this&#41;.getClass&#40;&#41;&#41;;
                          &#125;
                          else &#123;
                              builder.append&#40;f.get&#40;this&#41;&#41;;
                          &#125;
                      &#125;
                      catch &#40;IllegalAccessException e&#41; &#123;
                          //this can't happen. Would get a Security exception instead
                          //throw a runtime exception in case the impossible happens.
                          throw new InternalError&#40;"Unexpected IllegalAccessException"&#41;;
                      &#125;
                  &#125;
              &#125;
          &#125;
      &#125;
      Is it the class you want? And it was copied from the internet!

      Comment


      • #4
        I have solve the problem.the problem is that the f.get(this) is null,the code as follows:
        Code:
        private void hashCodeReflectionAppend&#40;Class clazz, HashCodeBuilder builder&#41; &#123;
                Field&#91;&#93; fields = clazz.getDeclaredFields&#40;&#41;;
                AccessibleObject.setAccessible&#40;fields, true&#41;;
                for &#40;int i = 0; i < fields.length; i++&#41; &#123;
                    Field f = fields&#91;i&#93;;
                    if &#40;&#40;f.getName&#40;&#41;.indexOf&#40;'$'&#41; == -1&#41; && &#40;!Modifier.isTransient&#40;f.getModifiers&#40;&#41;&#41;&#41;
                            && &#40;!Modifier.isStatic&#40;f.getModifiers&#40;&#41;&#41;&#41;&#41; &#123;
                        try &#123;
                            &#91;b&#93;if &#40;f.get&#40;this&#41; != null&#41; &#91;/b&#93;&#123;
                                if &#40;Collection.class.isAssignableFrom&#40;f.getType&#40;&#41;&#41;&#41; &#123;
                                    // System.out.println&#40;"BaseObject.java  " +
                                    // f.get&#40;this&#41;.getClass&#40;&#41;.toString&#40;&#41;&#41;;
                                    builder.append&#40;f.get&#40;this&#41;.getClass&#40;&#41;&#41;;
                                &#125;
                                else &#123;
                                    //   System.out.println&#40;"BaseObject.java " + f.get&#40;this&#41;.toString&#40;&#41;&#41;;
                                    builder.append&#40;f.get&#40;this&#41;&#41;;
                                &#125;
                            &#125;
                        &#125;
                        catch &#40;IllegalAccessException e&#41; &#123;
                            //this can't happen. Would get a Security exception instead
                            //throw a runtime exception in case the impossible happens.
                            throw new InternalError&#40;"Unexpected IllegalAccessException"&#41;;
                        &#125;
                        catch &#40;Exception e&#41; &#123;
                            System.out.println&#40;"BaseObject.java Error &#58;" + e.getMessage&#40;&#41;&#41;;
                        &#125;
                    &#125;
                &#125;
            &#125;

        Comment


        • #5
          In general I don't think reflective based toString() and hashCode() methods are a good idea. Every time I see them people are running into problems like this.

          rgds,
          Alef Arendsen

          Comment


          • #6
            ,Do you have a better way to solve the problem?

            thanks

            Comment

            Working...
            X