Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
### Changes

### version 3.32 on June 21, 2026

* Excludes javassist.tools.{reflect,rmi,web}. They are now included in ./examples/src/main.

* Disables javassist.runtime.Desc.useContextClassLoader

### version 3.31.0 on April 20, 2026

* GitHub PR #480, #484, #486, #491, #492, #495, #506
Expand Down
41 changes: 25 additions & 16 deletions Examples.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
How to run program examples
---------------------------

**Security notice:**
_All the programs are for demonstration only. They are not for production.
Additional security considerations and precautions are required
when applying these program in a production environment._

JDK 1.4 or later is needed.

### 0. If you have Apache Ant

Run the sample-all task.

```
% ant sample-all
```

Otherwise, follow the instructions below.

### 1. Move to the directory where this `Examples.md` file is located.
### 1. Move to the directory `./examples`.

In the following instructions, we assume that the `javassist.jar`
file is included in the class path.
For example, the javac and java commands must receive
the following `classpath` option:

```
-classpath ".:javassist.jar"
-classpath "./target:../javassist.jar"
```

If the operating system is Windows, the path
Expand All @@ -30,21 +40,20 @@ If you don't want to use the class-path option, you can make
environment:

```
export CLASSPATH=.:javassist.jar
export CLASSPATH=./target:../javassist.jar
```

or if the operating system is Windows:

```
set CLASSPATH=.;javassist.jar
set CLASSPATH=./target;../javassist.jar
```

Otherwise, you can copy `javassist.jar` to the directory
<_java-home_>`/jre/lib/ext`.

Then, compile `src/main/javassist/tools/**/*.java`:

<_java-home_> depends on the system. It is usually
`/usr/local/java` or `c:\j2sdk1.4\`, etc.
```
javac -d target -cp ./target:../javassist.jar src/main/javassist/tools/**/*.java
```

### 2. `sample/Test.java`

Expand All @@ -53,7 +62,7 @@ This is a very simple program using Javassist.
To run, type the commands:

```
% javac sample/Test.java
% javac -d target sample/Test.java
% java sample.Test
```

Expand All @@ -69,7 +78,7 @@ is called on the Person object.
To run, type the commands:

```
% javac sample/reflect/*.java
% javac -d target sample/reflect/*.java
% java javassist.tools.reflect.Loader sample.reflect.Main Joe
```

Expand Down Expand Up @@ -101,7 +110,7 @@ This is another example of reflective programming.
To run, type the commands:

```
% javac sample/duplicate/*.java
% javac -d target sample/duplicate/*.java
% java sample.duplicate.Main
```

Expand All @@ -122,9 +131,9 @@ a vector of a given type at compile time.
To run, type the commands:

```
% javac sample/vector/*.java
% javac -d target sample/preproc/*.java sample/vector/*.java
% java sample.preproc.Compiler sample/vector/Test.j
% javac sample/vector/Test.java
% javac -d target sample/vector/Test.java
% java sample.vector.Test
```

Expand All @@ -139,7 +148,7 @@ This demonstrates the `javassist.rmi` package.
To run, type the commands:

```
% javac sample/rmi/*.java
% javac -d target sample/rmi/*.java
% java sample.rmi.Counter 5001
```

Expand All @@ -165,7 +174,7 @@ existing class file under some restriction.
To run, type the commands:

```
% javac sample/evolve/*.java
% javac -d target sample/evolve/*.java
% java sample.evolve.DemoLoader 5003
```

Expand Down
48 changes: 39 additions & 9 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<project name="javassist" default="jar" basedir=".">

<property name="dist-version" value="javassist-3.31.0-GA"/>
<property name="dist-version" value="javassist-3.32.0-GA"/>

<property environment="env"/>
<property name="target.jar" value="javassist.jar"/>
Expand All @@ -20,6 +20,7 @@
<property name="test.build.dir" value="${build.dir}/test-classes"/>
<property name="test.run.dir" value="${build.dir}/runtest"/>
<property name="test.reports.dir" value = "${build.dir}/test-output"/>
<property name="examples.dir" value="${basedir}/examples"/>

<property name="run.dir" value="${build.classes.dir}"/>

Expand Down Expand Up @@ -144,7 +145,25 @@
</target>

<target name="sample" depends="compile">
<javac srcdir="${basedir}"
<javac srcdir="${examples.dir}/src/main"
destdir="${build.classes.dir}"
debug="on"
deprecation="on"
optimize="off"
includes="javassist/**">
<classpath refid="classpath"/>
</javac>

<javac srcdir="${examples.dir}/src/test"
destdir="${build.classes.dir}"
debug="on"
deprecation="on"
optimize="off"
includes="javassist/**">
<classpath refid="test.compile.classpath"/>
</javac>

<javac srcdir="${examples.dir}"
destdir="${build.classes.dir}"
debug="on"
deprecation="on"
Expand All @@ -154,10 +173,10 @@
<classpath refid="classpath"/>
</javac>

<copy file="sample/vector/Test.j"
<copy file="examples/sample/vector/Test.j"
todir="${build.classes.dir}/sample/vector"/>

<javac srcdir="${basedir}/sample/evolve"
<javac srcdir="${examples.dir}/sample/evolve"
destdir="${build.classes.dir}/sample/evolve/"
debug="on"
deprecation="on"
Expand All @@ -166,14 +185,14 @@
<classpath refid="classpath"/>
</javac>
<copy todir="${build.classes.dir}/sample/evolve">
<fileset dir="sample/evolve"/>
<fileset dir="${examples.dir}/sample/evolve"/>
</copy>
<copy file="${build.classes.dir}/sample/evolve/WebPage.class"
tofile="${build.classes.dir}/sample/evolve/WebPage.class.0"/>
<copy file="${build.classes.dir}/sample/evolve/sample/evolve/WebPage.class"
tofile="${build.classes.dir}/sample/evolve/WebPage.class.1"/>

<javac srcdir="${basedir}/sample/hotswap"
<javac srcdir="${examples.dir}/sample/hotswap"
destdir="${build.classes.dir}"
debug="on"
deprecation="on"
Expand All @@ -182,7 +201,7 @@
<classpath refid="classpath"/>
</javac>
<mkdir dir="${build.classes.dir}/logging"/>
<javac srcdir="${basedir}/sample/hotswap/logging"
<javac srcdir="${examples.dir}/sample/hotswap/logging"
destdir="${build.classes.dir}/logging"
debug="on"
deprecation="on"
Expand All @@ -194,6 +213,17 @@
to ${build.classes.dir}.</echo>
</target>

<target name="run-sample-test" depends="sample">
<junit fork="true" printsummary="true" dir="${test.run.dir}">
<classpath refid="test.classpath"/>
<formatter type="xml" extension=".xml"/>
<test name="javassist.tools.reflect.LoaderTest" outfile="TestLog" />
</junit>
<java fork="true" dir="${test.run.dir}" classname="javassist.tools.reflect.ClassMetaobjectTest">
<classpath refid="test.classpath"/>
</java>
</target>

<target name="jar" depends="compile18">
<jar jarfile="${target.jar}" update="true" manifest="${src.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build.classes.dir}">
Expand Down Expand Up @@ -234,7 +264,7 @@ Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.</i>]]></bottom>
<zip zipfile="${dist-version}.zip">
<zipfileset dir="${basedir}" prefix="${dist-version}">
<include name="html/**"/>
<include name="sample/**"/>
<include name="examples/**"/>
<include name="src/main/**"/>
<include name="tutorial/**"/>
<include name="*.html"/>
Expand Down Expand Up @@ -301,7 +331,7 @@ Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.</i>]]></bottom>
</target>

<target name = "sample-rmi" depends="sample" >
<echo>** Please open sample/rmi/webdemo.html with your browser **</echo>
<echo>** Please open examples/sample/rmi/webdemo.html with your browser **</echo>
<java fork="true" dir="${run.dir}" classname="sample.rmi.Counter">
<classpath refid="classpath"/>
<arg value="5001" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified javassist.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.31.0-GA</version>
<version>3.32.0-GA</version>
<packaging>bundle</packaging>
<name>Javassist</name>
<description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/javassist/CtClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class CtClass {
/**
* The version number of this release.
*/
public static final String version = "3.31.0-GA";
public static final String version = "3.32.0-GA";

private int linesCount = 0;

Expand Down
6 changes: 5 additions & 1 deletion src/main/javassist/bytecode/AttributeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ protected AttributeInfo(ConstPool cp, int n, DataInputStream in)
constPool = cp;
name = n;
int len = in.readInt();
info = new byte[len];
try {
info = new byte[len];
} catch (Throwable e) {
throw new IOException("Error reading attribute info for " + n + " with size " + len, e);
}
if (len > 0)
in.readFully(info);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/javassist/runtime/Desc.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public class Desc {
* <pre>Thread.currentThread().getContextClassLoader().loadClass()</pre>
* <p>If false, it is loaded by <code>Class.forName()</code>.
* The default value is false.
*
* @deprecated since 3.32. Use {@link setUseContextClassLoaderLocally()} instead.
*/
public static boolean useContextClassLoader = false;
private static boolean useContextClassLoader = false;

private static final ThreadLocal<Boolean> USE_CONTEXT_CLASS_LOADER_LOCALLY = new ThreadLocal<Boolean>() {
@Override
Expand Down
1 change: 0 additions & 1 deletion src/test/javassist/JvstTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,6 @@ public static Test suite() {
suite.addTestSuite(javassist.compiler.CompTest.class);
suite.addTestSuite(javassist.SetterTest.class);
suite.addTestSuite(javassist.bytecode.InsertGap0.class);
suite.addTestSuite(javassist.tools.reflect.LoaderTest.class);
suite.addTestSuite(javassist.tools.CallbackTest.class);
suite.addTestSuite(testproxy.ProxyTester.class);
suite.addTestSuite(testproxy.ProxyFactoryPerformanceTest.class); // remove?
Expand Down
5 changes: 2 additions & 3 deletions src/test/javassist/JvstTest4.java
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,9 @@ public void testJIRA151() {
// try it using classloader of TestDescForName Desc.useContextClassLoader = false;
assertTrue(javassist.runtime.Desc.getClazz("[Ljava.lang.String;") != null);
//Thread.currentThread().setContextClassLoader(TestDescForName.class.getClassLoader());
boolean old = javassist.runtime.Desc.useContextClassLoader;
javassist.runtime.Desc.useContextClassLoader = true;
javassist.runtime.Desc.setUseContextClassLoaderLocally();
assertTrue(javassist.runtime.Desc.getClazz("[Ljava.lang.String;") != null);
javassist.runtime.Desc.useContextClassLoader = old;
javassist.runtime.Desc.resetUseContextClassLoaderLocally();
}

public void testJIRA166() throws Exception {
Expand Down