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
10 changes: 8 additions & 2 deletions src/main/java/org/codehaus/plexus/build/BuildContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,16 @@ public interface BuildContext {
*
* @see #setValue(String, Object)
* @see #isIncremental()
* <p>
* The return type is inferred from the assignment target and is not checked here: a value of another type
* than the one the caller expects fails with a {@link ClassCastException} at the call site.
* </p>
*
* @param <T> the expected type of the value
* @param key a {@link java.lang.String} object.
* @return a {@link java.lang.Object} object.
* @return the value, or {@code null} if there is none
*/
Object getValue(String key);
<T> T getValue(String key);

/**
* <p>addWarning.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@
}

/** {@inheritDoc} */
public Object getValue(String key) {
@SuppressWarnings("unchecked")
public <T> T getValue(String key) {
if (isDefaultImplementation()) {
return contextMap.get(key);
return (T) contextMap.get(key);
}
return legacy.getValue(key);
return (T) legacy.getValue(key);
}

/** {@inheritDoc} */
Expand All @@ -168,12 +169,12 @@
}

/** {@inheritDoc} */
public void addError(File file, int line, int column, String message, Throwable cause) {

Check warning on line 172 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

addError(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 172 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / macos-latest jdk-25-zulu 3.10.0

addError(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 172 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-25-zulu 3.10.0

addError(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 172 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-8-zulu 3.10.0

addError(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 172 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-21-zulu 3.10.0

addError(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated
addMessage(file, line, column, message, SEVERITY_ERROR, cause);
}

/** {@inheritDoc} */
public void addWarning(File file, int line, int column, String message, Throwable cause) {

Check warning on line 177 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

addWarning(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 177 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / macos-latest jdk-25-zulu 3.10.0

addWarning(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 177 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-25-zulu 3.10.0

addWarning(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 177 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-8-zulu 3.10.0

addWarning(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 177 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-21-zulu 3.10.0

addWarning(java.io.File,int,int,java.lang.String,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated
addMessage(file, line, column, message, SEVERITY_WARNING, cause);
}

Expand All @@ -182,7 +183,7 @@
}

/** {@inheritDoc} */
public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {

Check warning on line 186 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

addMessage(java.io.File,int,int,java.lang.String,int,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 186 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / macos-latest jdk-25-zulu 3.10.0

addMessage(java.io.File,int,int,java.lang.String,int,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 186 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-25-zulu 3.10.0

addMessage(java.io.File,int,int,java.lang.String,int,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 186 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-8-zulu 3.10.0

addMessage(java.io.File,int,int,java.lang.String,int,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 186 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-21-zulu 3.10.0

addMessage(java.io.File,int,int,java.lang.String,int,java.lang.Throwable) in org.codehaus.plexus.build.BuildContext has been deprecated
if (isDefaultImplementation()) {
switch (severity) {
case BuildContext.SEVERITY_ERROR:
Expand All @@ -200,7 +201,7 @@
}

/** {@inheritDoc} */
public void removeMessages(File file) {

Check warning on line 204 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

removeMessages(java.io.File) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 204 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / macos-latest jdk-25-zulu 3.10.0

removeMessages(java.io.File) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 204 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-25-zulu 3.10.0

removeMessages(java.io.File) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 204 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-8-zulu 3.10.0

removeMessages(java.io.File) in org.codehaus.plexus.build.BuildContext has been deprecated

Check warning on line 204 in src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-21-zulu 3.10.0

removeMessages(java.io.File) in org.codehaus.plexus.build.BuildContext has been deprecated
if (isDefaultImplementation()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.codehaus.plexus.build;

/**
* Compile-time check that {@link BuildContext#getValue(String)} infers its result type from the assignment target, and
* that an implementation declaring the pre-generic {@code Object getValue(String)} still compiles. The module skips
* test execution, so this fails the build by not compiling.
*/
final class BuildContextGetValueTypingTest {

private BuildContextGetValueTypingTest() {}

static String inferredFromAssignment(BuildContext context) {
String value = context.getValue("key");
return value;
}

static Object plainObjectStillWorks(BuildContext context) {
Object value = context.getValue("key");
return value;
}

@SuppressWarnings({"unchecked", "rawtypes"})
abstract static class PreGenericImplementation implements BuildContext {
@Override
public Object getValue(String key) {
return null;
}
}
}
Loading