Skip to content

Cloneable #2

Closed
twillouer opened this Issue Dec 26, 2013 · 13 comments

2 participants

@twillouer

Hi,

I'm trying to use Immutable on a Cloneable object who redifined the clone() method:

    public static class CloneableA extends A implements Cloneable {

        public CloneableA clone() throws CloneNotSupportedException {
            return (CloneableA) super.clone();
        }
    }

    @Test
    public void given_AnObject_when_CreatingImmutableVersion_then_CloneableWorks()
            throws Exception {
        A a = new CloneableA();
        a.setI(10);
        A b = Immutable.of(a);
        Assert.assertEquals(10, b.getI());
    }

I got this stacktrace:

18:29:28.126 [main] DEBUG c.javax0.jscc.MemoryJavaFileManager - getJavaFileForOutput(CLASS_OUTPUT,com.javax0.immutator.PROXY$CLASS$SubFluent,CLASS,com.javax0.jscc.JavaSourceFromString[string:///PROXY$CLASS$SubFluent.java]
18:29:28.126 [main] DEBUG com.javax0.jscc.MemoryFileObject - Creating MemoryFileObject(com.javax0.immutator.PROXY$CLASS$SubFluent)
18:29:28.127 [main] DEBUG com.javax0.jscc.ByteClassLoader - findClass(com.javax0.immutator.PROXY$CLASS$SubFluent)

com.javax0.djcproxy.exceptions.ProxyClassCompilerError: /PROXY$CLASS$CloneableA.java:22: error: modifier volatile not allowed here
public volatile java.lang.Object clone(){
                                 ^
1 error

    at com.javax0.djcproxy.ProxyFactory.createClass(ProxyFactory.java:168)
    at com.javax0.djcproxy.ProxyFactory.create(ProxyFactory.java:133)
    at com.javax0.immutator.Immutable.of(Immutable.java:28)
    at com.javax0.immutator.ImmutableTest.given_AnObject_when_CreatingImmutableVersion_then_CloneableWorks(ImmutableTest.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


Process finished with exit code 255
@verhas verhas was assigned Dec 31, 2013
@verhas
Owner
verhas commented Jan 4, 2014

I have created a new branch to fix this issue. This also needs changes in the underlying libraries. They also have the same branch. The snapshot versions fix the issue. I hope to have time in the next two weeks, to create a new release. It would be great help if you (anyone) could test the snapshot versions.

@verhas
Owner
verhas commented Jan 4, 2014

I will close this issue with the next bug-fix release.

@twillouer

Hi,

I'm trying, but for now:
mvn clean install

given_AnObject_when_CreatingImmutableVersion_then_CloneableWorks(com.javax0.immutator.ImmutableTest): /PROXY$CLASS$CloneableA.java:22: error: modifier volatile not allowed here

Will try with -DskipTests later

@verhas
Owner
verhas commented Jan 4, 2014

You are probably checking out the master and not the bug fixing branch.

@twillouer

right, a mistake.

I download jscc, install the right branch, and when I try to compile djcproxy, I got a:

[ERROR] /home/william/src/djcproxy/src/main/java/com/javax0/djcproxy/ProxySourceFactory.java:[285,33] method exceptions in class com.javax0.jscglib.JSC cannot be applied to given types;
  required: java.lang.String[]
  found: java.lang.Class<?>[]
  reason: argument type java.lang.Class<?>[] does not conform to vararg element type java.lang.String

witch version of jdk do you use ?

@verhas
Owner
verhas commented Jan 6, 2014
@twillouer
/home/william/src/jscc [cloneable-bug] 10:13% mvn clean install 
[...]
[INFO] BUILD SUCCESS

/home/william/src/djcproxy [cloneable-bug] 10:15% mvn clean -X install
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: /usr/local/java/apache-maven-3.0
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-15-generic", arch: "amd64", family: "unix"
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project djcproxy: Compilation failure
[ERROR] /home/william/src/djcproxy/src/main/java/com/javax0/djcproxy/ProxySourceFactory.java:[285,33] method exceptions in class com.javax0.jscglib.JSC cannot be applied to given types;
[ERROR] required: java.lang.String[]
[ERROR] found: java.lang.Class<?>[]
[ERROR] reason: argument type java.lang.Class<?>[] does not conform to vararg element type java.lang.String
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project djcproxy: Compilation failure
/home/william/src/djcproxy/src/main/java/com/javax0/djcproxy/ProxySourceFactory.java:[285,33] method exceptions in class com.javax0.jscglib.JSC cannot be applied to given types;
  required: java.lang.String[]
  found: java.lang.Class<?>[]
  reason: argument type java.lang.Class<?>[] does not conform to vararg element type java.lang.String

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
/home/william/src/djcproxy/src/main/java/com/javax0/djcproxy/ProxySourceFactory.java:[285,33] method exceptions in class com.javax0.jscglib.JSC cannot be applied to given types;
  required: java.lang.String[]
  found: java.lang.Class<?>[]
  reason: argument type java.lang.Class<?>[] does not conform to vararg element type java.lang.String

        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:745)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:118)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
...

witch step does I miss ?
@verhas
Owner
verhas commented Jan 6, 2014

immutator uses jdcproxy
jdcproxy uses jscc and jscglib

I created branch cloneable-bug in the projects

  • immutator
  • jdcproxy
  • jscglib

I forgot to push the branch to jscglib. The project jscc was updated on the master, which is not a good style but since I am a small number of people being alone, this is not a big problem.

I will push the local changes this evening and hope to have a new release during week-end. Sorry for the inconvenience.

@twillouer

Any idea for a release date ?

@verhas
Owner
verhas commented Jan 24, 2014

If you could give a try to the code on the branch I created (also considering the dependent projects) and gave me feedback, that would increase my confidence and could help me a lot to be easy to merge the changes to master and do the release process.

@verhas
Owner
verhas commented Jan 25, 2014

I just released the 1.0.1 version of the library that should have this bug fixed.

@verhas verhas closed this Jan 25, 2014
@twillouer

Works better, but...

com.javax0.djcproxy.exceptions.ProxyClassCompilerError: /PROXY$CLASS$DwLocation.java:2: warning: Can't initialize javac processor due to (most likely) a class loader problem: java.lang.NoClassDefFoundError: com/sun/tools/javac/processing/JavacProcessingEnvironment
public class PROXY$CLASS$DwLocation extends com.deveryware.deveryflow.message.DwLocation implements com.javax0.djcproxy.ProxySetter{
       ^
    at lombok.javac.apt.Processor.init(Processor.java:84)
    at lombok.core.AnnotationProcessor$JavacDescriptor.want(AnnotationProcessor.java:89)
    at lombok.core.AnnotationProcessor.init(AnnotationProcessor.java:143)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:517)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:614)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:707)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    at com.sun.tools.javac.main.Main.compile(Main.java:439)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
    at com.javax0.jscc.Compiler.compile(Compiler.java:73)
    at com.javax0.djcproxy.ProxyFactory.createClass(ProxyFactory.java:165)
    at com.javax0.djcproxy.ProxyFactory.create(ProxyFactory.java:133)
    at com.javax0.immutator.Immutable.of(Immutable.java:28)

look likes it's a lombok/immutator compatibility problem.

Will try to reproduce.

@verhas
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.