Error optimizing program for method org.apache.commons.logging.LogFactory.createFactory(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/Object;:
var @factoryClass as factoryClass // 1
var @classLoader as classLoader // 2
var @logFactoryClass as logFactoryClass // 3
var @ex as ex // 18
var @e as e // 31
var @implementsLogFactory as implementsLogFactory // 50
var @msg as msg // 51
var @e_1 as e // 75
var @classLoader_1 as classLoader // 93
var @classLoader_2 as classLoader // 94
var @e_2 as e // 99
var @e_3 as e // 100
var @classLoader_3 as classLoader // 105
...
var @classLoader_9 as classLoader // 115
var @e_4 as e // 119
var @ex_1 as ex // 122
$0
initClass org.apache.commons.logging.LogFactory
goto $1
$1
at 'org/apache/commons/logging/LogFactory.java' 1012
nop
@logFactoryClass := null
at unknown location
goto $35
$2
@4 := phi @logFactoryClass from $35, @19 from $29, @32 from $25, @48 from $34
at 'org/apache/commons/logging/LogFactory.java' 1142
@5 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
if @5 == 0 then goto $5 else goto $6
catch java.lang.Exception goto $7
$3
at 'org/apache/commons/logging/LogFactory.java' 1020
@88 := new java.lang.NoSuchMethodError
@89 := 'Method not found: java.lang.ClassLoader.loadClass(Ljava/lang/String;)Ljava/lang/Class;'
invoke `java.lang.NoSuchMethodError.(Ljava/lang/String;)V` @88, @89
throw @88
catch java.lang.ClassNotFoundException goto $4
catch java.lang.NoClassDefFoundError goto $33
catch java.lang.ClassCastException goto $34
catch java.lang.Exception goto $7
$4
@ex := exception
@19 := phi @logFactoryClass from $3, @17 from $3
at 'org/apache/commons/logging/LogFactory.java' 1050
nop
@20 := field org.apache.commons.logging.LogFactory.thisClassLoader as `Ljava/lang/ClassLoader;`
if @classLoader !==@20 then goto $29 else goto $30
catch java.lang.Exception goto $7
$5
at 'org/apache/commons/logging/LogFactory.java' 1146
@6 := invokeStatic `java.lang.Class.forName(Ljava/lang/String;)Ljava/lang/Class;` @factoryClass
at 'org/apache/commons/logging/LogFactory.java' 1147
@7 := invoke `java.lang.Class.newInstance()Ljava/lang/Object;` @6
at unknown location
@133 := nullCheck @6
at 'org/apache/commons/logging/LogFactory.java' 1147
@8 := cast @7 to `Lorg/apache/commons/logging/LogFactory;`
at unknown location
goto $36
catch java.lang.Exception goto $7
$6
at 'org/apache/commons/logging/LogFactory.java' 1143
@9 := new java.lang.StringBuffer
invoke `java.lang.StringBuffer.()V` @9
@10 := 'Unable to load factory class via classloader '
@11 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @9, @10
@12 := invokeStatic `org.apache.commons.logging.LogFactory.objectId(Ljava/lang/Object;)Ljava/lang/String;` @classLoader_9
@13 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @11, @12
at unknown location
@134 := nullCheck @11
at 'org/apache/commons/logging/LogFactory.java' 1143
@14 := ' - trying the classloader associated with this LogFactory.'
@15 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @13, @14
at unknown location
@135 := nullCheck @13
at 'org/apache/commons/logging/LogFactory.java' 1143
@16 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @15
at unknown location
@136 := nullCheck @15
at 'org/apache/commons/logging/LogFactory.java' 1143
invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @16
at unknown location
goto $5
catch java.lang.Exception goto $7
$7
@e_1 := exception
@76 := phi @logFactoryClass from $35, @4 from $2, @4 from $5, @133 from $5, @4 from $6, @logFactoryClass from $3, @17 from $3, @19 from $4, @19 from $29, @19 from $30, @19 from $31, @19 from $32, @32 from $33, @32 from $25, @32 from $26, @32 from $27, @32 from $28, @48 from $34, @48 from $16, @48 from $17, @48 from $18, @48 from $19, @48 from $20, @48 from $21, @48 from $22, @48 from $23, @48 from $24
at 'org/apache/commons/logging/LogFactory.java' 1150
nop
@77 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
if @77 == 0 then goto $8 else goto $9
$8
at 'org/apache/commons/logging/LogFactory.java' 1153
if @76 === null then goto $10 else goto $11
$9
at 'org/apache/commons/logging/LogFactory.java' 1151
@87 := 'Unable to create LogFactory instance.'
invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @87
at unknown location
goto $8
$10
at 'org/apache/commons/logging/LogFactory.java' 1158
@78 := new org.apache.commons.logging.LogConfigurationException
at 'org/apache/commons/logging/LogConfigurationException.java' 55
nop
if @e_1 !== null then goto $37 else goto $38
$11
at 'org/apache/commons/logging/LogFactory.java' 1153
@79 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
if @79 !== null then goto $12 else goto $13
$12
at 'org/apache/commons/logging/LogFactory.java' 1153
@80 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
at unknown location
goto $14
$13
at 'org/apache/commons/logging/LogFactory.java' 1153
@81 := 'org.apache.commons.logging.LogFactory'
@82 := invokeStatic `org.apache.commons.logging.LogFactory.class$(Ljava/lang/String;)Ljava/lang/Class;` @81
field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory := @82 as `Ljava/lang/Class;`
goto $14
$14
@83 := phi @80 from $12, @82 from $13
at 'org/apache/commons/logging/LogFactory.java' 1153
@84 := invoke `java.lang.Class.isAssignableFrom(Ljava/lang/Class;)Z` @83, @76
at unknown location
@83 := nullCheck @83
at 'org/apache/commons/logging/LogFactory.java' 1153
if @84 != 0 then goto $10 else goto $15
$15
at 'org/apache/commons/logging/LogFactory.java' 1154
@85 := new org.apache.commons.logging.LogConfigurationException
@86 := 'The chosen LogFactory implementation does not extend LogFactory. Please check your configuration.'
invoke `org.apache.commons.logging.LogConfigurationException.(Ljava/lang/String;Ljava/lang/Throwable;)V` @85, @86, @e_1
return @85
$16
at 'org/apache/commons/logging/LogFactory.java' 1077
@implementsLogFactory := invokeStatic `org.apache.commons.logging.LogFactory.implementsLogFactory(Ljava/lang/Class;)Z` @48
at 'org/apache/commons/logging/LogFactory.java' 1084
nop
@msg := new java.lang.StringBuffer
invoke `java.lang.StringBuffer.()V` @msg
at 'org/apache/commons/logging/LogFactory.java' 1085
nop
@52 := 'The application has specified that a custom LogFactory implementation '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @52
at 'org/apache/commons/logging/LogFactory.java' 1086
@53 := 'should be used but Class \''
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @53
at 'org/apache/commons/logging/LogFactory.java' 1087
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @factoryClass
at 'org/apache/commons/logging/LogFactory.java' 1088
@54 := '\' cannot be converted to \''
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @54
at 'org/apache/commons/logging/LogFactory.java' 1089
@55 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
if @55 !== null then goto $17 else goto $18
catch java.lang.Exception goto $7
$17
at 'org/apache/commons/logging/LogFactory.java' 1089
@56 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
at unknown location
goto $19
catch java.lang.Exception goto $7
$18
at 'org/apache/commons/logging/LogFactory.java' 1089
@57 := 'org.apache.commons.logging.LogFactory'
@58 := invokeStatic `org.apache.commons.logging.LogFactory.class$(Ljava/lang/String;)Ljava/lang/Class;` @57
field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory := @58 as `Ljava/lang/Class;`
goto $19
catch java.lang.Exception goto $7
$19
@59 := phi @56 from $17, @58 from $18
at 'org/apache/commons/logging/LogFactory.java' 1089
@60 := invoke `java.lang.Class.getName()Ljava/lang/String;` @59
at unknown location
@59 := nullCheck @59
at 'org/apache/commons/logging/LogFactory.java' 1089
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @60
at 'org/apache/commons/logging/LogFactory.java' 1090
@61 := '\'. '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @61
at 'org/apache/commons/logging/LogFactory.java' 1091
if @implementsLogFactory == 0 then goto $20 else goto $21
catch java.lang.Exception goto $7
$20
at 'org/apache/commons/logging/LogFactory.java' 1100
@62 := 'Please check the custom implementation. '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @62
at unknown location
goto $22
catch java.lang.Exception goto $7
$21
at 'org/apache/commons/logging/LogFactory.java' 1092
@63 := 'The conflict is caused by the presence of multiple LogFactory classes '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @63
at 'org/apache/commons/logging/LogFactory.java' 1093
@64 := 'in incompatible classloaders. '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @64
at 'org/apache/commons/logging/LogFactory.java' 1094
@65 := 'Background can be found in http://commons.apache.org/logging/tech.html. '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @65
at 'org/apache/commons/logging/LogFactory.java' 1095
@66 := 'If you have not explicitly specified a custom LogFactory then it is likely '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @66
at 'org/apache/commons/logging/LogFactory.java' 1096
@67 := 'that the container has set one without your knowledge. '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @67
at 'org/apache/commons/logging/LogFactory.java' 1097
@68 := 'In this case, consider using the commons-logging-adapters.jar file or '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @68
at 'org/apache/commons/logging/LogFactory.java' 1098
@69 := 'specifying the standard LogFactory from the command line. '
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @69
goto $22
catch java.lang.Exception goto $7
$22
at 'org/apache/commons/logging/LogFactory.java' 1102
@70 := 'Help can be found @http://commons.apache.org/logging/troubleshooting.html.'
invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @70
at 'org/apache/commons/logging/LogFactory.java' 1104
@71 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
if @71 == 0 then goto $23 else goto $24
catch java.lang.Exception goto $7
$23
at 'org/apache/commons/logging/LogFactory.java' 1108
@72 := new java.lang.ClassCastException
@73 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @msg
invoke `java.lang.ClassCastException.(Ljava/lang/String;)V` @72, @73
throw @72
catch java.lang.Exception goto $7
$24
at 'org/apache/commons/logging/LogFactory.java' 1105
@74 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @msg
invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @74
at unknown location
goto $23
catch java.lang.Exception goto $7
$25
at 'org/apache/commons/logging/LogFactory.java' 1123
goto $2
catch java.lang.Exception goto $7
$26
at 'org/apache/commons/logging/LogFactory.java' 1062
@34 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
if @34 == 0 then goto $27 else goto $28
catch java.lang.Exception goto $7
$27
at 'org/apache/commons/logging/LogFactory.java' 1067
throw @e
catch java.lang.Exception goto $7
$28
at 'org/apache/commons/logging/LogFactory.java' 1063
@35 := new java.lang.StringBuffer
invoke `java.lang.StringBuffer.()V` @35
@36 := 'Class \''
@37 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @35, @36
@38 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @37, @factoryClass
at unknown location
@37 := nullCheck @37
at 'org/apache/commons/logging/LogFactory.java' 1063
@39 := '\' cannot be loaded'
@40 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @38, @39
at unknown location
@38 := nullCheck @38
at 'org/apache/commons/logging/LogFactory.java' 1063
@41 := ' via classloader '
@42 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @40, @41
at unknown location
@40 := nullCheck @40
at 'org/apache/commons/logging/LogFactory.java' 1063
@43 := invokeStatic `org.apache.commons.logging.LogFactory.objectId(Ljava/lang/Object;)Ljava/lang/String;` @classLoader
@44 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @42, @43
at unknown location
@42 := nullCheck @42
at 'org/apache/commons/logging/LogFactory.java' 1063
@45 := ' - it depends on some other class that cannot be found.'
@46 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @44, @45
at unknown location
@44 := nullCheck @44
at 'org/apache/commons/logging/LogFactory.java' 1063
@47 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @46
at unknown location
@46 := nullCheck @46
at 'org/apache/commons/logging/LogFactory.java' 1063
invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @47
at unknown location
goto $27
catch java.lang.Exception goto $7
$29
at 'org/apache/commons/logging/LogFactory.java' 1123
goto $2
catch java.lang.Exception goto $7
$30
at 'org/apache/commons/logging/LogFactory.java' 1052
@21 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
if @21 == 0 then goto $31 else goto $32
catch java.lang.Exception goto $7
$31
at 'org/apache/commons/logging/LogFactory.java' 1056
throw @ex
catch java.lang.Exception goto $7
$32
at 'org/apache/commons/logging/LogFactory.java' 1053
@22 := new java.lang.StringBuffer
invoke `java.lang.StringBuffer.()V` @22
@23 := 'Unable to locate any class called \''
@24 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @22, @23
@25 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @24, @factoryClass
at unknown location
@24 := nullCheck @24
at 'org/apache/commons/logging/LogFactory.java' 1053
@26 := '\' via classloader '
@27 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @25, @26
at unknown location
@25 := nullCheck @25
at 'org/apache/commons/logging/LogFactory.java' 1053
@28 := invokeStatic `org.apache.commons.logging.LogFactory.objectId(Ljava/lang/Object;)Ljava/lang/String;` @classLoader
@29 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @27, @28
at unknown location
@27 := nullCheck @27
at 'org/apache/commons/logging/LogFactory.java' 1053
@30 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @29
at unknown location
@29 := nullCheck @29
at 'org/apache/commons/logging/LogFactory.java' 1053
invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @30
at unknown location
goto $31
catch java.lang.Exception goto $7
$33
@e := exception
@32 := phi @logFactoryClass from $3, @17 from $3
at 'org/apache/commons/logging/LogFactory.java' 1060
nop
@33 := field org.apache.commons.logging.LogFactory.thisClassLoader as `Ljava/lang/ClassLoader;`
if @classLoader !==@33 then goto $25 else goto $26
catch java.lang.Exception goto $7
$34
@48 := phi @logFactoryClass from $3, @17 from $3
at 'org/apache/commons/logging/LogFactory.java' 1071
nop
@49 := field org.apache.commons.logging.LogFactory.thisClassLoader as `Ljava/lang/ClassLoader;`
if @classLoader !==@49 then goto $2 else goto $16
catch java.lang.Exception goto $7
$35
at 'org/apache/commons/logging/LogFactory.java' 1014
nop
if @classLoader === null then goto $2 else goto $3
catch java.lang.Exception goto $7
$36
at 'org/apache/commons/logging/LogFactory.java' 1147
return @8
$37
at 'org/apache/commons/logging/LogConfigurationException.java' 55
@90 := invokeVirtual `java.lang.Throwable.toString()Ljava/lang/String;` @e_1
at unknown location
goto $39
$38
at 'org/apache/commons/logging/LogConfigurationException.java' 55
@91 := null
goto $39
$39
@92 := phi @90 from $37, @91 from $38
at 'org/apache/commons/logging/LogConfigurationException.java' 55
invoke `org.apache.commons.logging.LogConfigurationException.(Ljava/lang/String;Ljava/lang/Throwable;)V` @78, @92, @e_1
at 'org/apache/commons/logging/LogFactory.java' 1158
return @78
Unexpected error occurred: java.lang.AssertionError: Variable used before definition: @17 at $3
This may happen if you have logger implementation like this:
//...
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//...
public class Test{
Logger log = LoggerFactory.getLogger(Test.class);
//...
//...
//...
}
pom:
Solution:
TeaVM has its own logging mechanism which logs not only on console, but also on browser Developer Console like javascript’s console.log() :
Make sure to remove any dependencies that depends on apache commons-logging (e.g. htmlunit ). To make sure run:
mvn dependency:tree
in project directory. This should display a list of all library dependencies throughout entire project like this:
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- net.sourceforge.htmlunit:htmlunit:jar:2.15:compile
[INFO] | +- xalan:xalan:jar:2.7.1:compile
[INFO] | | \- xalan:serializer:jar:2.7.1:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.3.3:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] | +- org.apache.httpcomponents:httpmime:jar:4.3.3:compile
[INFO] | +- commons-codec:commons-codec:jar:1.9:compile
[INFO] | +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.15:compile
[INFO] | +- xerces:xercesImpl:jar:2.11.0:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.21:compile
[INFO] | +- net.sourceforge.cssparser:cssparser:jar:0.9.14:compile
[INFO] | | \- org.w3c.css:sac:jar:1.3:compile
[INFO] | +- commons-io:commons-io:jar:2.4:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] | \- org.eclipse.jetty:jetty-websocket:jar:8.1.15.v20140411:compile
[INFO] | +- org.eclipse.jetty:jetty-util:jar:8.1.15.v20140411:compile
[INFO] | +- org.eclipse.jetty:jetty-io:jar:8.1.15.v20140411:compile
[INFO] | \- org.eclipse.jetty:jetty-http:jar:8.1.15.v20140411:compile
[INFO] +- com.google.code.gson:gson:jar:2.9.0:compile
[INFO] +- org.jsoup:jsoup:jar:1.15.1:compile
Get rid of any dependency that relies on apache commons-logging as TeaVM has very little support of external libraries:
Add following dependencies for logging:
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-extras-slf4j</artifactId>
<version>0.7.0</version>
</dependency>
Also make sure to set javascript optimization level to SIMPLE instead of FULL which might cause longer build-time and unintended failed built msg, in pom.xml:
import org.teavm.extras.slf4j.TeaVMLogger;
import org.teavm.extras.slf4j.TeaVMLoggerFactorySubstitution;
//...
//...
//...
public class Client {
public static TeaVMLogger log = (TeaVMLogger) TeaVMLoggerFactorySubstitution.getLogger(Client.class);
public static void main(String[] args) {
log.info("Starting...");
//...
//...
//...
log.debug("Some Debug Info...");
//...
//...
}
}
Running sample:
run: mvn clean package
open: target/teavm-logging-demo-1.0-SNAPSHOT/index.html in browser.
No comments:
Post a Comment